Launching GUI App in CentOS Docker Container

Rishabh Jain
4 min readMay 31, 2021

Hello Everyone ,

Today I am going to launch GUI Applications like Firefox, Jupyter notebook inside docker container.

Task Description 📄

📌 GUI container on the Docker

🔅 Launch a container on docker in GUI mode

🔅 Run any GUI software on the container

Pre-requisite :

✔ Docker should be installed in a System.

Let’ Start :-

Steps to follow :-

1. Check whether Docker is installed in your system or not, run the following to command to check it out.

docker info

2. To use docker first we have to start docker services. And make it enable so it will be on start mode permanently.

systemctl start docker
systemctl enable docker

3. It’s time to pull image from DockerHub to our base OS Red Hat Enterprise Linux 8.

docker pull centos:latest

# Here, I am using CentOS latest image. To see downloaded images in docker

docker images

4. Type “export DISPLAY=:0”

export DISPLAY=:0

What is the meaning of this Command ?

The environment variable DISPLAY tells GUI programs on how to communicate with the GUI. A Unix system can run multiple X servers, i.e. multiple displays. These displays can be physical displays (one or more monitor), or remote displays (forwarded over the network, e.g. over SSH), or virtual displays such as Xvfb, etc. The basic syntax to specify displays is HOST: NUMBER; if you omit the HOST part, the display is a local one.

5. Restart The Docker Service

systemctl restart docker 

# The Service of Docker Should start Otherwise it should give some errors

6. After the start of Docker service then you should type the Docker run command with the use of X11 Port.

docker run -it -v /tmp/.X11-unix/:/tmp/.X11-unix/ -e DISPLAY=$DISPLAY centos bash

Before executing this command, let’s understand what this command will exactly do.

  • docker run -ti --rm

-i sets up an interactive session; -t allocates a pseudo tty; --rm makes this container ephemeral.

  • -e DISPLAY=$DISPLAY

-e sets the host display to the local machine's display.

  • -v /tmp/.X11-unix:/tmp/.X11-unix

-v bind mounts the X11 socket residing in /tmp/.X11-unix on your local machine into /tmp/.X11-unix in the container.

7. Now install any GUI Application inside container. Here I am installing Firefox.

yum install firefox -y

8. Run the “firefox” command, and hopefully, you will see your Firefox Web-Browser is running inside the Docker container.

The Firefox Will take GUI from the Linux port X11.

firefox
Mozilla Firefox running

Now it Works perfectly.

We have some warnings but we can also remove that by installing some packages and softwares.

9. Now Let’s install jupyter notebook.

But for installing jupyter notebook we first need to install python3.

yum install python3 -y
pip3 install jupyter

10. Installation is complete launch jupyter notebook.

Note :- We will be launching jupyter notebook in root user so we need to allow root user to use it.

jupyter notebook --allow-root

# Now, we got the token, so note this token and give it whenever it requires.

Jupyter notebook running

Well Done, we have launched Jupyter Notebook Successfully on Docker Container.

Hope you understood the concept and performed this task with me.

Thank you for reading my article🤗

For any help or suggestions find me on LinkedIn.

--

--