Running GUI Application on the top of Docker Container

Atharva Jagtap
3 min readJun 1, 2021

Docker is a software platform that allows you to build, test, and deploy applications quickly. Docker packages software into standardized units called containers that have everything the software needs to run including libraries, system tools, code, and runtime.

Docker Containerise two types of application-

  1. Applications that run as a Background Service like a Database, WebServer, etc.
  2. GUI Applications that run in the foreground.

This article will show you how to Containerise GUI Application inside a Docker Container. Here we will be Launching Jupyter Notebook inside a Docker Container. For a GUI Application to run, we need to have a XServer which we are going to have by

  1. Sharing Host Display Environment Variable.
 $ --env=“DISPLAY”

2. Running the Host network drive.

$ --net=host

Lets get started with steps involved in launching a GUI Application inside a Docker Container.

Step 1:

Assure DISPLAY environment variable to be :0(most of the time its :0).

$ echo $DISPLAY
Checking DISPLAY Environment Variable value

But exception can be there due to your display than for that export the DISPLAY environment variable to :0 value

$ export DISPLAY=:0
export display

Step 2: Command add the user( Client ) to the list of allowed connection for the X-server.

$ xhost +
User get list of allowed connection connection for the X-server

Step 3:

Run the Docker container using the command.

$ sudo docker run -it — env=”DISPLAY” — net=host — name ML_OPsTask2 centos:latest
Docker container

Step 4:

After that install firefox using the cmd.

# yum install firefox
Install firefox

Step 5:

After the installation of firefox now install python3 and jupyter notebook using the cmd.

# yum install python3 -y && pip3 install jupyter
Installation Jupyter Notebook

Step 6:

Run firefox and see the result of launching the firefox application on the Docker container.

Running firefox

Step 7:

Now run the Jupyter Notebook using cmd

# jupyter notebook — allow-root
Running Jupyter Notebook

I hope that you had enjoyed the article and learned a new concept today :D

For any query contact me through my Linkedin profile mentioned below.

--

--