vnc连接远程服务器中docker容器的桌面

安装vnc

参考这个

通过VNC搭建Ubuntu 18.04和20.04图形界面
https://help.aliyun.com/document_detail/59330.html

用下面这段话替换 ~/.vnc/xstartup
vim ~/.vnc/xstartup

#!/bin/sh
# Uncomment the following two lines for normal desktop:
export XKL_XMODMAP_DISABLE=1
 unset SESSION_MANAGER
# exec /etc/X11/xinit/xinitrc
unset DBUS_SESSION_BUS_ADDRESS
[ -x /etc/vnc/xstartup ] && exec /etc/vnc/xstartup
[ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources
xsetroot -solid grey
vncconfig -iconic &
#x-terminal-emulator -geometry 80x24+10+10 -ls -title "$VNCDESKTOP Desktop" &
# x-window-manager &
gnome-session &
gnome-panel &
gnome-settings-daemon &
metacity &
nautilus &
gnome-terminal 
# :wq保存退出

开启vnc服务

vncserver -geometry 1920x1080 :1
vncserver -kill :1 #结束服务,不关一直在

服务器连接docker vnc

在服务器的vncviewer中地址为
172.17.0.2:1
密码是123456
(实际地址为172.17.0.2:5901,tightvncserver和vnc4server都会给地址加5900,x11vnc保持不变)

在这里插入图片描述

服务器端口映射

把服务器对应ip端口172.17.0.2:5901映射到本地主机127.0.0.1:5901上

ssh -L 5901:172.17.0.2:5901 [email protected]

在本地主机的vnc viewer中连接
在这里插入图片描述
连上了

在这里插入图片描述

存在问题,不能开终端,没有桌面。解决方法应该是改~/.vnc/xstartup里面的内容,网上有很多版本,不知道应该用哪一个。

猜你喜欢

转载自blog.csdn.net/qq_43488795/article/details/125187934