GUI APPLICATION ON DOCKER CONTAINER

suyog shinde
3 min readMar 16, 2021

--

What is Docker?

Docker is a set of the platform as service products that use OS-level virtualization to deliver software in packages called containers.

Docker advantages

Docker containers provide a way to build and deploy applications that is easier to assemble, maintain, and manage. Therefore, Docker containers are stateless. The resources used by docker containers are very minimal. Docker containers provide high speed. They are easy to scale.

What is a dockerfile?

To build Docker images we use dockerfile. It’s a simple text file that is easy to understand and maintain, they include instructions to build the docker image. The docker file consists of environmental variables, network port, and other components.

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 baseOS.

There are two types of applications:-

  1. Background and Foreground

The foreground applications require a GUI ( For example Gedit, Chrome)

Foreground application requires Xserver.

What is 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

Here, We are going to use a remote system as a docker container.

The X server provides the following basic types of services:

  • Input handling
  • Window services
  • Graphics
  • Text and fonts

We are going to launch Firefox on container:

So, let’s start with practical.

While launching the container we need to specify three things

share the Host’s XServer with the Container by creating a volume

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

Environmental Variable

 — env=”DISPLAY”

sharing from base OS, So I need a network i.e, host

 — net= ”host”

We are going to run firefox on top of the container:

Now let’s create a docker file for creating a container:

vim Dockerfile

Use this Dockerfile to build an image with a GUI application

sudo docker build -t gui-app .

After this let’s launch the container with GUI Application (Chrome)

sudo docker run --net=host --env="DISPLAY" 
--volume="$HOME/.Xauthority:/root/.Xauthority:rw" gui-app

Now we can see the GUI application on the display of the host machine.

Happy Learning ✏️

Keep Learning !! Keep Sharing !!

Thank you for reading 📰📰📰📰

Contact me📱 :

https://www.linkedin.com/in/suyogshinde/

--

--