Running GUI Applications in Docker Container.

Rohit Raut
2 min readApr 24, 2021

In this article, we are going to launch a GUI application in the Docker container. According to your use case, you can run any GUI application inside docker. In my case, I am using the Firefox web browser application.

Pre-requisite: Docker should be installed in your virtual machine.

Create customized docker image:

Let's say we want to run any application inside the docker container process. So, first, we have to install the software. Instead of installing every time when we create a container process. We can create a customized container image that has the software. This process is called creating a customized docker image or docker build. For this, the best approach to create an image is “Dockerfile”.

The name of the Dockerfile (Default is ‘PATH/Dockerfile’) but if you want to change you can pass file name with option -f and path

Dockerfile

FROM centos:latest
RUN yum install firefox -y
RUN yum install gedit -y

To build image

docker build -tag <imagename:version> path

To run any GUI application

we need Xserver which is available in every Linux desktop environment and containers don't have it. So we need to share it from the base operating system

1.We need to run the container with the host network driver

--net=host

2. We need to share the DISPLAY environmental variable to the container

--env="DISPLAY"

3. Share hosts Xserver by creating container volume.

--volume=$HOME/.Xauthority:/root/.Xauthority:rw

That all we have to do.

follow me for more technological articles.

Thank you for reading...

--

--