Launching a GUI application on the top of Docker Container

Gaurav Tank
3 min readMay 30, 2021

Hello everyone, in this blog, I am going to tell you how we can run a GUI application inside a Docker container.

Pre-requisites

  1. Docker should be downloaded and configured on a Linux system

After completing all the pre-requisites we can follow these simple steps:

Step1: Pull the docker image. You can use any container image. Here, I am using centos: latest

docker pull centos:latest

Step2: Run the docker container

docker run -it --net=host --env="DISPLAY" --name CONTAINER_NAME centos:latest

While running the docker container, it is mandatory to specify the net= host so that the container will use the local network for the network connection and env= DISPLAY. Because we need to run a GUI application on the top of the container that’s why we need to set an environment as a display.

After running this command a new terminal screen will appear.

This / sign means that we are not in our local machine but in our GUI container.

Step3: Install the required packages

yum install python3 firefox

Step4: Install the required libraries for python3 to run the code

pip3 install jupyter sklearn

Now, our environment is all set up. We need to launch the Jupiter notebook from the command line.

jupyter notebook --allow-root

That’s all, our jupyter notebook is launched on the top of a Docker container

Jupyter notebook running on the top of a Docker Container

BONUS

In case you are having some trouble setting up the environment, I have also created my own custom image for launching Jupiter notebook on the top of the container. I used the concept of Dockerfile for creating it.

You can also use my custom image by entering the following command

docker pull gaurav2203/gui:latest

This will directly download the image on your local workspace. Then for running the container use this command.

docker run -it --net=host --env="DISPLAY" --name CONTAINER_NAME gaurav2203/gui:latest

This will directly launch the Jupiter notebook.

You can also find the code of Dockerfile here.

Thank you for reading hope you find this blog useful.

--

--