Configure VNC and novnc inside the docker container, accessible from the host or external

Recently, the project just needs to be used. After configuring it, there are mainly three tools: 1. tigervnc, 2. xfce4 3. novnc

1. The installation of tigervnc apt can be used to provide the service of vncserver

apt install tigervnc-standalone-server tigervnc-common

2. xfce4 provides desktop services, relatively lightweight

apt install xfce4 xfce4-goodies xorg dbus-x11 x11-xserver-utils

3. novnc can be downloaded directly from github

git clone https://github.com/novnc/noVNC.git

First follow the steps to configure the startup script. This is a reference to this blog to prevent the blog from becoming invalid. I hereby paste it here.

# 创建启动脚本
touch $HOME/.vnc/xstartup

# 执行此命令之前在容器内安装了vim
vim $HOME/.vnc/xstartup

## 添加以下脚本(如果有乱码,删除脚本中的中文配置)
#!/bin/sh

unset SESSION_MANAGER 
unset DBUS_SESSION_BUS_ADDRESS 
startxfce4 &    #启动xface4
[ -x /etc/vnc/xstartup ] && exec /etc/vnc/xstartup 
[ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources 
xsetroot -solid grey    #设置背景色

# 保存并关闭文件。无论何时启动或者重启TigerVNC服务器,都将会自动执行上述命令

# 使用chmod
chmod +x ~/.vnc/xstartup

Start a window of nvcserver, -localhost no means that vnc can be accessed externally, not just localhost, the window here: 1 is 5901, :2 corresponds to 5902

vncserver :2 -localhost no

View currently running windows:

vncserver -localhost novncserver -list

start novnc

./utils/novnc_proxy --vnc localhost:5902 --web /home/noVNC

There may be errors when starting novnc, similar to: 

400 Client must support 'binary' or 'base64' protocol

This error can be solved by modifying websock.js, there is a corresponding issue

Solved editing file /novnc/core/websock.js
Locate line:
this._websocket = new WebSocket(uri, protocols);
replace with
this._websocket = new WebSocket(uri, ['binary', 'base64']); //protocols);

After this configuration, as long as our container opens the mapping of port 6080 to the outside, then we can access the desktop inside the container with vnc

Guess you like

Origin blog.csdn.net/qq_31638535/article/details/131016239