Runing a GUI container on the Docker

parthanaboina praveen
3 min readNov 2, 2021

Runing a GUI container on the Docker

suppose you are 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.

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 eg: firefox,jupyter

so, for any GUI application to run , we need to have XSERVER which is already availble in all linux systems

Lets understand what is XServer?

The X server 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.

while lauching a container By sharing Host’s XServer , host display environment and host net , to the container then we can loads the Xserver modules at run time .

lets launch a container in GUI mode

docker run -it --name jupteros --env="DISPLAY" --net=host--volume="$HOME/.Xauthority:/root/.Xauthority:rw"

“-it “ option means interactive terminal. It will help us to interact with the os by providing the shell i.e terminal

We can share the Host’s XServer with the container by creating a volume

--volume="$HOME/.Xauthority:/root/.Xauthority:rw"

We have to provbide this as a option to share docker host i.e in our case RHEL8 XServer.

  • We have to share the host display environment to the container.
--env="DISPLAY"
  • Also, we have to run container with host network.
--net=host

Now, we have a new container created named as jupyteros with the image centos in GUI MODE

Now, run command yum install python3 to install python inside docker container.

Now, lets install jupyter. Run command

# pip3 install jupyter

Now, to run jupyter notebook, we should have a browser. So here i am installing firefox browser inside the container using command

# yum install firefox -y

Now, our environment is ready inside docker container.

Now, run the command jupyter notebook — allow-root

Thanks for reading .

--

--