How to run Fedora GUI in Docker – just 6 commands

Docker is great for experimenting and testing server an applications. But what about GUI? How is it possible to run application which requires GUI in Docker container?

There are several ways how to access GUI application from the container. E.g. using ssh tunnel with X-Forwarding. The downside of this approach is speed and responsiveness of UI.

Much better responsiveness has TigerVNC server with VNC client.

Let’s pull and run Fedora image. We will also open a port 5901 where we can connect with VNC client:

docker run -p 5901:5901 -it fedora /bin/bash

Now install some basic applications. We will use TigerVNC server to serve the UI. Then we will use Fluxbox as a window manager because it’s small and versatile. We will need also xterm to invoke our commands.

yum -y install fluxbox tigervnc-server xterm

In a classic desktop installation of Fedora we’re using Display manager which allows to type user’s login. This is not necessary for Docker and instead of starting XServer we will launch TigerVNC server which will launch Fluxbox for us.

Write following configuration to ~/.vnc/xtasrtup:

mkdir -p ~/.vnc
echo "fluxbox &"> ~/.vnc/xstartup
chmod u+x ~/.vnc/xstartup

Now we can start the VNC server:

vncserver

It will prompt you for a password for protecting the connection. Just enter a password of your choice.

The server will automatically bind to 5901.

Now let’s start VNC Client on the host machine (I recommend RealVNC, because it’s fast and easy to use) and connect it to localhost:5901.

Here is the result:

If you need to invoke context menu in Fluxbox just right click with mouse.

You can stop TigerVNC server by command:

vncserver -kill :1