GUI CONTAINER ON THE DOCKER

Docker is the best tool you can use if you want to develop one single application that can run and work uniformly at any environment, laptop or public cloud instance thanks to its convergent virtualized packages called containers!!

Prasantmahato
4 min readMar 11, 2021

--

Real-life use cases of Docker

  • Environment standardization. Since Docker documented instructions in how to create an environment with a Dockerfile, you can minimize the inconsistency between different environments. …
  • Faster configuration with consistency. …
  • Better disaster recovery. …
  • Improvement in adoption of DevOps.

After reading above lines and some recent research on it ,I can conclude there is very less used case where docker container is used for GUI purpose .

If we want a GUI Program run on the Docker Container ,We need to understand some basic things .

If I want to run and deploy some UI application on top of the Docker Container .I have to connect the display of the Docker container with the display of base OS ,as container is mainly designed with the minimal resources ,So that in a second .., Enviornment can be deleted and deployed easily .

We have to understand there are two types of Applications :-

  1. Application which are designed to be runned in background .(For ex: WebServer)
  2. Application which are designed to be runned in Foreground . (For ex: Firefox)

Remember application which runs on foreground always require XServer .

XServer is always present on the linux system .As I am using RHEL8 as my base OS, I can run the application on top of the base OS which has been launched on docker container .

Before moving Forward lets know,

What does X Server mean?

X server is a server program that connects X terminals running on the X Window System, whether locally or in a distributed network. The X server is installed with the X Window System, which is a cross-platform and complete client-server system for managing graphical user interfaces on a single computer or networked ones. The X server manages the X clients and does the actual work in terms of managing input and display devices and performing requested operations. This simplifies programming, as the application programs themselves do not need to be aware of the hardware details and just rely entirely on the X server.

Now to share the Host’s XServer with container ,I created a volume and then shared .

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

As I provided the Host’s XServer but it needs a enviornment where it would display the enviornment to us .

— env=”DISPLAY”

As we are only using the container to launch the applications and rest everything I am sharing from base OS ,So I need a network

— net=host

I started my practical by using Dockerfile ,as it is a very good practise to create an image .

Inside Dockerfile

vim Dockerfile

FROM centos:latest
RUN yum install firefox -y
CMD [“/usr/bin/firefox”]

Building an image with my username of docker hub attached so that I can upload the image to the docker hub.

docker build -t prasant1998/firefox-gui:v1 .

We can confirm the image is created by using ..

docker images

Now pushing to the docker hub

docker push prasant1998/firefox-gui:v1

We can confirm the image is successfully uploaded to the docker hub by using..

Pulling image from the docker hub

docker pull prasant1998/firefox-gui:v1

Now launch the Container using the image

docker run — net=host — env=”DISPLAY” — volume=”$HOME/.Xauthority:/root/.Xauthority:rw” prasant1998/firefox-gui:v1

We can see now firefox is launched which has been running inside the Docker Container.

Open for any Queries and Suggestions .

Thankyou

--

--