0.基础指令# 查看容器dockerpsdockerimages1.删除旧容器dockerrm-fnovnc-test2/dev/null2.删除旧镜像dockerrmi ubuntu-novnc-vnc:22.042/dev/null3.确认删除情况dockerps-a|grepnovnc-testdockerimages|grepubuntu-novnc-vnc4.重新加载镜像cddocker-imagesdockerload-iubuntu-novnc-vnc-22.04.tardockerimages|grepubuntu-novnc-vnc5.映射容器GPU驱动dockerrun-d--namenovnc-test--gpusall-p2222:22 ubuntu-novnc-vnc:22.04dockerrun-d--namenovnc-test--gpusall-p2222:22-v/longhorn/workspace:/workspace ubuntu-novnc-vnc:22.04dockerrun-d\--namenovnc-test\--gpusall\--cap-addNET_ADMIN\--device/dev/net/tun\-p2222:22\-v/longhorn/workspace:/root/workspace\ubuntu-novnc-vnc:22.046.进入容器dockerexec-itnovnc-testbash7.安装sshaptupdateaptinstall-yopenssh-servermkdir-p/run/sshdechoroot:1|chpasswdsed-is/^#\\?PermitRootLogin.*/PermitRootLogin yes//etc/ssh/sshd_configsed-is/^#\\?PasswordAuthentication.*/PasswordAuthentication yes//etc/ssh/sshd_configservicesshrestart||/etc/init.d/ssh restart||(/usr/sbin/sshd)echoSSH 配置完成自动退出容器exit0dockerexec-itnovnc-testsh-lcsed -ri s/^#?PermitRootLogin.*/PermitRootLogin yes/; s/^#?PasswordAuthentication.*/PasswordAuthentication yes/ /etc/ssh/sshd_configdockerexec-itnovnc-testsh-lcservice ssh restart || /etc/init.d/ssh restart || pkill sshd; /usr/sbin/sshd sleep 18.端口防火墙设置firewall-cmd--permanent--add-port2222/tcp firewall-cmd--reloadfirewall-cmd --list-ports|grep2222# 验证防火墙dockerps--filternamenovnc-testdockerport novnc-test ss-lntp|grep22229.运行跳板转发# 允许 ProxyJump/端口转发sed-is/^AllowTcpForwarding no/AllowTcpForwarding yes//etc/ssh/sshd_configgrep-q^PermitOpen/etc/ssh/sshd_config||echoPermitOpen any/etc/ssh/sshd_config sshd-tsystemctl restart sshd# 验证grep-nEAllowTcpForwarding|PermitOpen/etc/ssh/sshd_config10.本机连接(带VNC)Host k3s-node02 HostName172.16.108.22 User root Port22# 第一个容器原来的Host NVIDIA HostName127.0.0.1 User root Port2222ProxyJump k3s-node02 LocalForward6080127.0.0.1:6080 ServerAliveInterval30ServerAliveCountMax3# 第二个容器新增的Host NVIDIA2 HostName127.0.0.1 User root Port2223# 这里改成 2223ProxyJump k3s-node02 LocalForward6081127.0.0.1:6081# 这里改成 6081ServerAliveInterval30ServerAliveCountMax3http://localhost:6080 http://localhost:608111.本地连接# 命令行验证ssh-vNVIDIAssh-N-L2222:127.0.0.1:2222 root172.16.108.22