Docker-Vnc Desktop Configuration.

This is an automatically translated post by LLM. The original post is in Chinese. If you find any translation errors, please leave a comment to help me improve the translation. Thanks!

When using public servers, users typically have regular user accounts with limited permissions, unable to configure the server freely according to their preferences. To meet this demand, Docker is often used to allow root privileges within containers for environment configuration. VNC, a commonly used remote desktop tool, facilitates server-side rendering of graphical interfaces, which is particularly useful for experiments requiring interfaces (such as mujoco, habitat, igibson environments). This article mainly discusses configuring VNC desktop within Docker and provides a pre-packaged image: kezhiadore/ubuntu-vnc - Docker Image | Docker Hub

It's lovely rubbish

First, start from an initial Ubuntu 18.04 image, download, launch, and enter the container:

1
2
3
docker pull ubuntu:bionic
docker run -itd --name ubuntu-vnc ubuntu:bionic
docker exec -it ubuntu-vnc

As this container doesn't have a desktop, install the xfce4 desktop:

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

Then, install vncserver after entering:

1
2
apt update
apt install tigervnc-standalone-server tigervnc-common

Configure startup files in the user directory:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
apt install vim
vim ~/.vnc/xstartup

## Add the following script

#!/bin/sh
unset SESSION_MANAGER
unset DBUS_SESSION_BUS_ADDRESS
startxfce4 &
[ -x /etc/vnc/xstartup ] && exec /etc/vnc/xstartup
[ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources
xsetroot -solid grey

# Save and close the file. The above commands will be executed automatically whenever starting or restarting the TigerVNC server.

# Change file permissions
chmod +x ~/.vnc/xstartup

Start vncserver:

1
vncserver :1

The vncserver needs initial configuration for passwords. Once configured, use a vnc client to access port 5091 to connect to the remote desktop.

Tips

Reference

  1. Configuring VNC and novnc inside Docker containers, accessible from the host or externally
  2. Visualizing Docker containers using VNC
  3. Ubuntu Docker Container with VNC Desktop