Launching A GUI Software On Docker Container

Jayesh Kumar
4 min readMay 30, 2021

This is very simple , we need to make some changes in ‘xhost’ so that docker container can use DISPLAY of the host .

Here I’ll be using Redhat linux as a host and centos image to launch docker container .

Now you might be thinking what is ‘xhost’ :-

If I give a simple definition then , the xhost command is a server access control program for X server . xhost command adds or deletes host names on the list of machines from which the X Server accepts connections. This command must be run from the machine with the display connection.

Now might be thinking what is ‘X server’ :-

X is an application that manages one or more graphics displays and one or more input devices (keyboard, mouse, etc.) connected to the computer.

It works as a server and can run on the local computer or on another computer on the network. Services can communicate with the X server to display graphical interfaces and receive input from the user.

As the above poster mentioned, X is a server (meaning a program which other programs call upon and be called by) which is responsible for creating a graphical environment and if it fails for whatever reason, you'll be greeted by Command Line Interface (CLI).

If some ask me to define it in very brief then ‘ X server is program called by other program to provide them with a graphical screen’

Now we will see how can launch a graphical software( for eg. firefox ) on Docker container which provide us CLI :

Here we are using redhat linux as a host

First : we have run command ‘ echo $DISPLAY ’ why?

It is so because every graphical screen or DISPLAY has on number . We can find this number by running this command , which will help our CLI to know on which DISPLAY it can run itself .

Second: we have export our DISPLAY so that anyone can use it .

Third : then we run ‘xhost +’ we used it to allow any program to access our DISPLAY.

Fourth : Then we created a Dockerfile

Fifth : Here is our Dockerfile , in this we are defining that we are using centos image , updating our yum repo , installing( python3 , firefox , jupyter) , and defining that firefox is the graphical software we have to run

Sixth : Now we build or Dockerfile with command ‘ docker build -t gui:v1 . ’

Here gui is our image name (we can give any ), v1 is the version ( we can give any) and we have used ‘ . ’ to tell that we are running this command in place where we have Dockerfile .

Seventh : Now we launch our container using command ‘ docker run -ti

— —net=host — env=“DISPLAY” gui:v1 ’

Here we use net=host to define that container has to use host network , we defined env=“DISPLAY” which tells the container which display to use , we use image named by us as ‘gui’ and defined the version v1.

Finally we have achieved firefox gui on docker cli .

Thankyou everyone : )