Run GUI Application inside docker

Arjun Chauhan
3 min readMar 13, 2021

--

Docker is one of the most common container technology. Docker is a set of platform as a service (PaaS) products that use OS-level virtualization to deliver software in packages called containers.

Docker makes application deployment very fast and efficient. Containers are isolated from one another and bundle their own software, libraries and configuration files; they can communicate with each other through well-defined channels.

Mostly the command line is enough for the docker commands and tasks. This has lead to a common believe that GUI is not supported by the docker. However this is not the case . We can enable GUI in docker.

Today we are going to just that.

I would be launching the firefox in the docker container.

So let’s begin

The whole procedure I would be explaining in detail. Sometimes however when we go deep we tend to lose track. So let’s first lay down the steps:

  1. download centos docker image
  2. create a new image with firefox installed
  3. Build that image
  4. enable GUI support
  5. Launch the new container

downloading the centos image

I currently have the docker image. You can however use

docker pull centos:latest

to download the image.

Firstly let’s see if we try to launch the firefox application normally in default setting.

While inside the container I tried to launch the firefox application and we can see that the error shows that the environment variable is not displayed.

Now I would be creating the docker image using the docker file.

This is a very tiny docker file because the use case we are dealing with involves only launching the firefox using GUI.

Firstly this dockerfile creates a container from centos:latest image. Then it installs firefox on the container. The third command tells it to launch the firefox command.

So far so good. The docker image is successfully built.

So the only catch here is to launch a container with DISPLAY variable set.

While creating the container I specified the DISPLAY variable. This seems to be running. So let’s see if we have a new window of firefox open.

So you can see a new tab in the firefox is open. I am running the system on RHEL8 OS. The page however that pops up is showing the CENT OS which is the image of the container we launched. This means we have successfully launched a GUI application from the docker environment.

This was a small practical we did today, however it proved us that launching GUI application is very much possible in a dockerized environment.

--

--