š³Running GUI Applications inside Docker Containersš³

While the IT world is embracing Containers Technology primarily for Enterprise Server Applications, there is also a huge scope of Docker Containers impacting the Desktop and Development Environment.

Docker is a set of the platform as service products that use OS-level virtualization to deliver software in packages called containers.
What are the issues while launching a GUI application?
Docker doesnāt come with GUI as there is are minimal use cases with it. So, if we want to run GUI applications on a docker container then we need a display, as the container is not connected to the display. We need to connect the display of Base-OS.
There can be two types of applications (usually services) that you can containerize
- Applications that run as a Background Service (like a Database, webserver)
- GUI Applications that run in the foreground (like firefox, jupyter notebook)
Foreground applications requires Xserver

X is an application that manages one or more graphical displays and inputs like (keyboard, mouse, webcam etc.) connected to the computer. X is the GUI protocol for Linux/Unix system.
So, Services communicate with the X-server to display a graphical interface and receive input from the user and the X-server clients can be on the remote system.
For a GUI Application to run, we need to have a XServer which is available as part of every Linux Desktop Environment, But within a Container we donāt have any XServer ā so we will
- Share the Hostās XServer with the Container by creating a volume
--volume="$HOME/.Xauthority:/root/.Xauthority:rw"
- Share the Hostās DISPLAY environment variable to the Container
--env="DISPLAY"
- Run container with host network driver with
--net=host
So letās get started
First we have to start the docker service
# systemctl start docker
# systemctl enable docker
# systemctl status docker

Command to pull image
# docker pull centos:latest

Now letās create a Dockerfile for creating docker image for GUI:
vim Dockerfile
cat Dockerfile

Use this Dockerfile to build an image with a GUI application for running jupyter notebook inside docker container
docker build -t jupyter-gui .


After this letās launch the container from our created docker image jupyter-gui
# docker run --name jupyter --net=host --env="DISPLAY" --volume="$HOME/.Xauthority:/root/.Xauthority:rw" jupyter-gui:latest



Thanks for reading !!!šāØ keep learning! keep growing!