Running remote GUI applications on a docker container
Introduction
This wiki explains how to prepare a docker container to run GUI applications. In addition, the applications are available for remote usage, making it possible to install applications on a server and run them on your workstations.
X2Go makes possible this task, enabling you to enter the GUI of your container and use the GUI application remotely without the -X overhead on the network.
Fulfilling the dependencies
Creating a container with Ubuntu (from docker server shell)
From your docker server terminal, create the container with the following commands:
# Pull the ubuntu image docker pull ubuntu # Create the container CONTAINER_NAME=my_container sudo docker run -itd --name $CONTAINER_NAME -p 2222:22 ubuntu /bin/bash
The -p
argument exposes port 22 of your container to port 2222 of your host. That means that you can access to port 22 of your container from your <hostip>:2222
The following steps require you enter to your container shell. To open it, go to the docker server and execute:
CONTAINER=my_container docker exec -ti $CONTAINER /bin/bash
Creating a container with Ubuntu (from Portainer)
From Portainer, please, add a new container. You can follow the next images in order to get ready.
In the left sidebar, click on Containers and then on Add Container. It will display the following view:

Fill the form with the data shown in the picture:
- Name: my_container
- Image: ubuntu:latest
- In Port mapping, map additional port and add 2222 on host and 22 on container. This will redirect the traffic from your server at port 2222 to the container to the port 22.
- Command:
/bin/bash
- Console: Interactive & TTY
After deploying your container:

Click on Console:

You will need console access for the next steps.
Install SSH
You need to be able to connect to your container through SSH. As a first step, install SSH:
apt update apt install sudo ssh
Warning: The SSH service will not start on container boot. You need to create an entrypoint to get it on start up. If you want to start SSH manually, you can use:
service ssh start
Create an user
The next step is to create a user for remote access. Please, take a look at the following commands:
USERNAME=myusername adduser $USERNAME
It will ask you for entering your password and other details. Fill the fields and, then, make it a sudoer:
usermod -aG sudo $USERNAME
Install a graphic desktop to your container
X2Go makes it possible to access a GUI installed in the container. However, the most common Ubuntu images do not have a graphical desktop installed by default. In this case, we recommend XFCE due to its lightweight.
sudo apt-get install -y xfce4
Install X2Go
Please, type the following commands to install X2Go server:
sudo apt-get install software-properties-common -y sudo add-apt-repository ppa:x2go/stable sudo apt-get update sudo apt-get install x2goserver x2goserver-xsession -y
Make sure that SSH server is running. Check it running:
service ssh status
It should show:
● ssh.service - OpenBSD Secure Shell server Loaded: loaded (/lib/systemd/system/ssh.service; enabled; vendor preset: enab Active: active (running) since jue 2019-08-08 13:27:58 CST; 1 day 1h ago Process: 5709 ExecReload=/bin/kill -HUP $MAINPID (code=exited, status=0/SUCCES Process: 5703 ExecReload=/usr/sbin/sshd -t (code=exited, status=0/SUCCESS) Main PID: 1196 (sshd) CGroup: /system.slice/ssh.service └─1196 /usr/sbin/sshd -D
It is currently "active".
Accessing to your container with X2Go client
X2Go requires you to install a client on the host(local computer). Please, install in your client X2Go Client:
sudo apt install x2goclient # Run x2goclient
After installing the client, create a new session:

Then, fill the form which opens after clicking the highlighted icon:

In Your machine name, type a personalized name for your session. In Container IP, type the IP of the container to access with X2Go. Also, type your username and select the Session Type with the Graphical Desktop which you installed in the container. In our case, it is XFCE.
After registering the new, in the X2go client window will appear a sidebar on the right with your session:

Double click your session and enter the container's password in the modal window.

Result
After entering your credentials, a new window will appear with your container GUI. In our case, it is the XFCE desktop:

Possible issues
There are elements that can cause issues with your X2Go client.
- SSH is down: remember to start the SSH service. You can do it from your container shell with
sudo service ssh start
- Container is not connected to a bridge network. It is important to connect the container to a bridge network. If you cannot get access to the bridge network, you can show port 22 by port mapping when creating your container.
For direct inquiries, please refer to the contact information available on our Contact page. Alternatively, you may complete and submit the form provided at the same link. We will respond to your request at our earliest opportunity.
Links to RidgeRun Resources and RidgeRun Artificial Intelligence Solutions can be found in the footer below.