Running a GUI software on Docker Container

Mohammed Abdul Basith
4 min readAug 20, 2021

Summer Task_2:
Task Description 📄
📌 GUI container on the Docker
🔅 Launch a container on docker in GUI mode
🔅 Run any GUI software on the container

What is Docker ?

Docker is a set of platform as a service (PaaS) products that use OS-level virtualization to deliver software in packages called containers. Containers are isolated from one another and bundle their own software, libraries and configuration files; they can communicate with each other through well-defined channels. Because all of the containers share the services of a single operating system kernel, they use fewer resources than virtual machines.

NOW LETS START :-

We are basically building a UI application and deploying it on a docker container. If you want that UI application to display the user interface screen on your local machine while running the application inside the docker container, you will have to connect the display of the Docker container with the display of Local Machine. So, here we want Jupyter Notebook which runs on a browser to be run inside docker container.

Let suppose, you want to run Jupyter notebook inside a Docker container. So first, lets have a look at type of applications and how it runs. There are majorly two types of applications that can be containerized.

  1. Applications that run as a Background service eg: webserver
  2. GUI Application that run in foreground

So, for any GUI application to run, we need to have XServer which is already available in all Linux systems.

What is XServer ?

The XServer is a single binary executable(/usr/x11R6/bin/Xorg)[in rhel8] that dynamically loads any necessary X server modules at runtime from the /usr/X11R6/lib/modules/ directory. Some of these modules are automatically loaded by the server, while other are optional. The X server and its configuration files are stored in /etc/X11/ directory. The configuration file of X server is /etc/X11/xorg.conf.

But, when we launch a container, we don’t have Xserver configured here, so what we can do is,

  • we can share the Host’s XServer with the container by creating a volume.

— volume = “$HOME/.Xauthority:/root/.Xauthority:rw”

we have to share the host display environment to the container.

— env= “DISPLAY”

Also we have to run container by providing these options.

— net=host

Now let’s begin with the practical,

Pre-requisite for this practical: yum configured, docker installed and enabled on your system.

Step 1. Pull the centos image

First of all you have to install docker image. You can choose any image for it. Here i am going to install centos latest image by this command.

Step 2. Lunch a container

Main step to launch gui application on docker container is here. With run command we have to pass some paramenters which are discussed above. Command is :

  1. docker run -it — name lwtask2 — net=host — env=”DISPLAY” — volume=”$HOME/.Xauthority:/root/.Xauthority:rw” centos:latest

In my case , name of container is lwtask2, you can give any name according to your choice.

Step. 3 Install packages in docker container.

After launching the container , now we have to install some packages/softwares in it.

First we install python3 with the following command,

yum install python3 -y

Next step is to install jupyter notebook. We can install this with pip3 command,

pip3 install jupyter

Till Here We are done with all installations.

Step 4. launch GUI application on docker.

Now let’s launch jupyter notebook, but it is not preferred to launch jupyter notebook with root account directly. So here we have to use — allow-root option with our command,

so command to launch jupyter notebook will be like:

jupyter notebook — allow-root

Jupyter Notebook is launched successfully on docker container.

Task Completed!

Thank you…

#vimaldaga #righteducation #educationredefine
#rightmentor #worldrecordholder#linuxworld#makingindiafutureready

--

--