Analytics Vidhya
Published in

Analytics Vidhya

Making a container go GUI

🔅 Launch a container on docker in GUI mode
🔅 Run any GUI software on the container

A GUI (graphical user interface) is a system of interactive visual components for computer software. A GUI displays objects that convey information, and represent actions that can be taken by the user. The objects change color, size, or visibility when the user interacts with them.

But why use a GUI?
GUI though not as powerful as CLI or code, but is definitely more user-friendly. If you are a coder, you may know the horrors of not having an IDE in your arsenal for developing a code, you may want the comfort of having a browser to check in your web-app, some tools like Jenkins are hard to use unless you have a proper CLI to connect to, you may want to see your code fail in a fantastic GUI fashioned show of colors… the possibilities are endless folks!!!

But how exactly can we make a container run GUI application in it?
Let’s find out…

By doing a simple google search about it we can find that when someone tries to run a GUI application over a container, the error is about some missing variable with name X11 display, on further googling this error we can learn that the error is about a missing environmental variable with name DISPLAY, which is required by X11 to run a GUI program. To solve this we can launch our container with -e option to define DISPLAY. The variable DISPLAY is required to tell exactly where the display is located before launching the terminal itself.



  • hostname is the name of the computer where the X server runs. An omitted hostname means the localhost.
  • D is a sequence number (usually 0). It can be varied if there are multiple displays connected to one computer.
  • S is the screen number. A display can actually have multiple screens. Usually there’s only one screen though where 0 is the default.

Usually we can set the variable with a value exactly equals to the value of DISPLAY in the host computer, hence we can use the command
docker run <options> -e DISPLAY=$DISPLAY <image>
to set the variable.

But this is not all. We would also require to have the X11 configured, to do that we can again use the configuration in the base OS to configure the container. How? Well it’s simple we just need to forward the volume /tmp/X11-unix to the same location inside the container. Hence the command is now transformed to:
docker run <OPTIONS> -e DISLAY=$DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unix <IMAGE>
Here .X11-unix is a socket file that is required by X11 server to connect to its client(applications like Firefox)

Now this method can be used to make some particular container work with GUI tools in it. But say we require to use a GUI tool in a container with image say Centos:7, if we try to perform this type of operation there, we again land up with a bunch of errors telling us that our machine is not GUI capable or something. What to do now?
The simple solution that we have found for solving this error is to install some package groups that would install all the required software and tools to run GUI applications.

Now, with all this knowledge let’s try to make a Centos:7 container run Firefox, and if it works let’s see if we can run a IDE like Jupyter to work on the container or not.

Step1: Pull the required image…
For this you can use the command docker pull centos:7

Step2: Use the pulled image to launch a container…

We’ll use this container to make a GUI enabled image with Centos:7 as a base.

Step3: Install the package group. We’ve installed a package group with the name of ‘Server with GUI’ as it will install Firefox for me.

This step may take a while… you may consider taking a nap or watch a movie or something until the installation is finished. You know this step is the only reason we would want to make a image out of it once we are at it.
After the installation is finished we are eligible to move on to the next step

Step4: Commit the container. Now all you have to do is to make a image out of the container you spend like a day making. To do so we can run a command docker commit <container> <new image name>:<tags for your image>
In our case the command may looks like:

docker ps will help you to find the name of your image.

Step5: Test. To test out your image, you can launch a container with the new image. To do this we would use a command like:

You can then run the GUI app to test, in my case I used the Firefox command, which will launch Firefox browser for us.
Note the ID of the container is 178d2acb6406, this same ID can be seen on the Firefox browser…

ID is marked on the top bar

As we can see the container ID matches the ID shown by the browser, which suggest that the Firefox is running over the container rather than the base OS.

Now if you want to run a Jupyter IDE, we can also do that. Just use the following set of commands to launch the IDE

  1. yum install -y python3
  2. pip install jupyter
  3. jupyter notebook --allow-root

If you follow the commands you’ll end up with a screen like:

CLI screen for output and the browser result

There are also some other ways we can achieve GUI capabilities over a container, one of them includes SSH. However if you do want to achieve the results like this without the hassle of making the image you can pull the image made by us by using the command:
docker pull prithvirajsingh1604/task:gui01
click here for more info.

This task was completed in collaboration with Divya Kurothe and I would like to thank her for helping me finish this task effectively through her supportive efforts.

That’s all folks, task completed successfully (∩^o^)⊃━☆
Thank you for giving this a read, you rock ヾ(⌐■_■)ノ♪




Analytics Vidhya is a community of Analytics and Data Science professionals. We are building the next-gen data science ecosystem

Recommended from Medium

Long Story Short: Siddhi - A view of a contributor

7 Reasons Why Java Development is so Popular for Enterprise Software

Why Java Development is so Popular for Enterprise Software

Role of Start and Run methods in Multi-threading

Guide: How to Speed up Your Python Continuous Integration Pipeline in Azure DevOps Using Dependency…

The Business Case for Agile Deployments & a CI/CD Pipeline

Innovation Is Compounding Interest:

Serverless is beautiful — Part 1

Istio Service Mesh: The Step by Step Guide

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Prithviraj Singh

Prithviraj Singh

More from Medium

Reduce your docker image size with .dockerignore

Did I really just commit and push a file with a password in it?-Remove

[Ubuntu 20.04][MySQL5.7]Problems installing mysql5.7 on Ubuntu 20.04

Install darktable 3.8.1 on Ubuntu / OpenSUSE / Fedora & AlmaLinux