Desktop in Docker

We’re building a new training program around Apache Airflow. The major technical challenge with delivering this sort of program is ensuring that everybody in the class has access to a working version of the technology. Since there is generally a diverse range of setups (operating systems, corporate firewalls and personal configurations) this can really be a nightmare.

We want to offer a uniform experience for everybody in the class. But it also needs to be something that is easy for us to configure and manage.

So I’ve been exploring the option of running a desktop in Docker. There are a number of suitable images and I’m going to try out a couple of them here.

Ubuntu & LXDE

The first image that I tried was centminmod/docker-ubuntu-vnc-desktop. To get started, pull the image. There’s only one tag available: latest.

docker pull centminmod/docker-ubuntu-vnc-desktop

The dorowu/ubuntu-desktop-lxde-vnc image (which I use in the next post) provides a similar interface but appears to be more actively maintained. It also has a selection of tags giving access to various versions of Ubuntu.

HTTP Client

Now run it, mapping port 80 on the container to port 8080 on the host.

docker run -p 8080:80 centminmod/docker-ubuntu-vnc-desktop

The resulting container will immediately download a netboot.xyz ISO. This is not cached locally, so it gets downloaded each time you launch a container. But the ISO is pretty small (just over 2 MiB), so it’s quick and painless.

To view the desktop go to http://127.0.0.1:8080/ in your browser. It’s a LXDE desktop, which is lightweight but has everything that we need.

An LXDE desktop accessible via HTTP.

📢 If the desktop doesn’t fill the window, then simply refresh the page in your browser.

VNC Client

Alternatively, you can connect using a VNC client. Start a new container, mapping port 5900 onto the host.

docker run -p 5900:5900 centminmod/docker-ubuntu-vnc-desktop

Go to 127.0.0.1:5900 in your VNC client.

An LXDE desktop accessible via VNC.

💡 The HTTP client we accessed before uses noVNC, a JavaScript VNC client.

Shared Memory

You’ll probably want to expose the host’s shared memory to the container, so add in the -v /dev/shm:/dev/shm and --ipc=host options to docker run.

Customising

You can use a selection of environment variables to customise the container:

  • -e HTTP_PASSWORD — password for HTTP authentication
  • -e VNC_PASSWORD — password for VNC authentication
  • -e RESOLUTION — resolution (for example, 1920x1080)
  • -e USER — desktop user (default is root) and
  • -e PASSWORD — desktop password.

Ubuntu & XFCE

The consol/ubuntu-xfce-vnc image provides a XFCE desktop. There’s also an IceWM version.

Pull the image. There’s a selection of versioned tags, but we’ll just go with latest.

docker pull centminmod/docker-ubuntu-vnc-desktop

HTTP & VNC Clients

Let’s expose both HTTP and VNC clients (this can also be done with the previous image).

docker run -p 5900:5901 -p 8080:6901 consol/ubuntu-xfce-vnc

Browse to http://127.0.0.1:8080/vnc.html for the full client. Press the Connect button and provide “vncpassword” as the password. Alternatively, go to http://127.0.0.1:8080/?password=vncpassword for the lightweight client.

An XFCE desktop accessible via HTTP.

Connect via VNC client to 127.0.0.1:5900. The password is “vncpassword”.

An XFCE desktop accessible via VNC.

Customising

Use the following environment variables to customise:

  • -e VNC_PW — password for VNC
  • -e VNC_COL_DEPTH — colour depth and
  • -e VNC_RESOLUTION — resolution.

Shit Happens

After working with these images for a while I ended up getting this error.

noVNC encountered an error.

Not sure what the problem was, but I cleared the cached web content in my browser and the issue was resolved.

What’s Next?

Next I’m going to use one of these images to set up an environment for working with Airflow.