Bernhard's Homepage

GNS3 - Create a Docker VM with VNC Console

GNS3 - Create a Docker VM with VNC Console

If you want to use graphical clients within Docker VMs, GNS3 expects the container to use X11 to display its contents. The conversion to VNC is done by the GNS3 server, NOT by the Docker container. So you don’t have to install any VNC stuff in your Docker image, just install the X11 clients like Firefox.

While you don’t have access to the main CLI console, you can start an auxiliary console (right-click on the device and select “Auxiliary console”). This creates a telnet console, which can start both cli commands, that run in the auxiliary console, and GUI commands, that are shown in the VNC window.

To start your GUI application during the start of the container, either set CMD in the Dockerfile or use the “Start command” in the GNS3 docker template.

As an example here a simple Firefox application, I’m calling it ffox.

The Dockerfile for docker build:

FROM ubuntu
RUN apt-get update
RUN apt-get -y install firefox

If you want to use the image directly on the linux system (outside GNS3) run:

xhost +local:
docker run -it -e DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unix ffox firefox

Within GNS3 create a template using “firefox” as a start command:

Docker Template

Create a project:

Docker Project

In GNS3 the network interfaces are NOT managed by Docker, the interfaces are created by GNS3 and injected into the container. The network configuration is done with a config file in Debian network/interfaces syntax. Right-click on the node and use “Edit config” to edit the network configuration (while the node is stopped).

Here I’m using DHCP on interface eth0:

Docker Interface Configuration

Now, when starting this container, you should see Firefox running within the VNC console:

Docker VNC Console #1

But as you notice, there is no window manager running in the Docker container. So you can’t modify the size or position of the Firefox application and you can’t start other applications.

Therefore my GNS3 docker images contain jwm as a very small window manager, here a basic Dockerfile:

FROM ubuntu
RUN apt-get update
RUN apt-get -y install firefox jwm lxterminal
RUN sed -i 's/xterm/x-terminal-emulator/g' /etc/jwm/system.jwmrc
CMD sh -c "firefox & jwm"

Instead of using start commands in the Docker template, I prefer to use CMD. That way the user doesn’t need to know, how to correctly start the container. To make use of CMD, the start command in the Docker template/node needs to be empty.

Don’t run this image outside GNS3, as its jwm window manager wants to overtake your local window manager. And you don’t want to run into this mess.

The window manager enables the normal ways to interact with the windows. You can now move, resize and minimize them. A start menu allows to run further applications.

Docker VNC Console #2

But the issues, when running it outside GNS3, makes this Docker image unsafe to use. It would be far better to run the window manager only, when the VM is used within GNS3.

The following Dockerfile starts jwm only, when no other window manager is active. As this gets too complex to put it into a CMD line, a startup script /etc/init.sh is used.

FROM ubuntu
RUN apt-get update
RUN apt-get -y install firefox jwm lxterminal wmctrl
RUN sed -i 's/xterm/x-terminal-emulator/g' /etc/jwm/system.jwmrc

#
# startup script
#
RUN printf '\
\043!/bin/sh\n\
\n\
firefox &\n\
\n\
wmctrl -m > /dev/null 2>&1 && wait $! || jwm\n' \
        > /etc/init.sh && chmod +x /etc/init.sh

CMD [ "/etc/init.sh" ]

Now the Docker image is safe to use outside GNS3, it no longer conflicts with a local window manager.

With this background information you might want to have a look at https://github.com/GNS3/gns3-registry/blob/master/docker/ipterm/web/Dockerfile to see, how the official Firefox Docker appliance is built.