GUI APPLICATION INSIDE DOCKER CONTAINER

sonu kushwaha
3 min readFeb 10, 2022

What is Docker?

Docker is a tool designed to make it easier to create, deploy, and run applications by using containers. Containers allow a developer to package up an application with all of the parts it needs, such as libraries and other dependencies, and deploy it as one package. By doing so, thanks to the container, the developer can rest assured that the application will run on any other Linux machine regardless of any customized settings that the machine might have that could differ from the machine used for writing and testing the code.

In a way, Docker is a bit like a virtual machine. But unlike a virtual machine, rather than creating a whole virtual operating system, Docker allows applications to use the same Linux kernel as the system that they’re running on and only requires applications to be shipped with things not already running on the host computer. This gives a significant performance boost and reduces the size of the application.

Types of applications (usually services) that you can containerize:

Applications that run as a Background Service (like a Database, WebServer, etc)

GUI Applications that run in the foreground.

Today, we are going to see the second option:

X Window System/ X:

X11 is the current version of the X Window System.

X provides the basic framework for a GUI environment: drawing and moving windows on the display device and interacting with a mouse and keyboard. X does not mandate the user interface — this is handled by individual programs. As such, the visual styling of X-based environments varies greatly; different programs may present radically different interfaces.on Unix-like operating systems.

For a GUI Application to run, we need to have an XServer which is available as part of every Linux Desktop Environment.

Run the following command to see the X Server and X Client running on your Linux Machine:

$ ps -aux | grep X

For Windows, you can use Xming.

For OSX, you can use Xquarkz.

But within a Container, we don’t have any XServer — so we will:

Mount the X11 socket residing in /tmp/.X11-unix on your local machine into /tmp/.X11-unix in the container.

-v /tmp/.X11-unix:/tmp/.X11-unix

share the Host’s DISPLAY environment variable to the Container

-e DISPLAY=$DISPLAY

run container with host network driver with

— net=host

Example 1: Dockerfile to build an image with a sample GUI application (Firefox):

$ cat Dockerfile

FROM centos:7

RUN yum install -y firefoX

CMD [“/usr/bin/firefox”]

$ sudo docker build -t sonukushwaha403/firefox .

Docker Hub: https://hub.docker.com/repository/docker/sonukushwaha403/firefox

$ sudo docker run -it — rm -e DISPLAY=$DISPLAY — net=host sonukushwaha403/firefox

You should see the firefox GUI application now displayed on your Host OS Desktop.

--

--