GUI application in docker container

Shivani Mandloi
3 min readJun 1, 2021

Can you run GUI apps on Docker?

Most of us till now containerize applications that we want to keep on running for example like Databases, Web servers, etc.

There are a lot of myths that we cannot run GUI applications and software on Docker containers but there is a way using which we can run GUI applications and software on a docker container within seconds

So let's try this,

Task Description 📄

◼ GUI container on the Docker

◼ Launch a container on docker in GUI mode

◼ Run any GUI software on the container

Concept:

Normally, Whenever we run any GUI application in our machine it tries to connect with the X server. The X server is a windowing system for bitmap displays, common on Unix-like operating systems. X provides the basic framework for a GUI environment.

but docker containers do not have such X server but it can use hosts X server

That is for X server it doesn’t matter which application from where making request, simple we can run a GUI application in a docker container and will try to connect it with X11 port i.e X server which is running on the host machine.

so let's start,

◼ Prerequisites:

Your host machine should have docker configures and running

Step1: To create an image with any GUI application first we will write a docker file using which we will build the docker image,

Create a workspace first,

# mkdir dockerGui

create a file named “Dockerfile” make sure to create a file name with the same case because while building image docker search for file names “Dockerfile”.

#vim Dockerfile

here I am using firefox as a GUI application, so installing firefox and “/usr/bin/firefox” will run firefox as soon as my container launch

Creating docker image,

Running a docker container using the image created above,

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

and share the Host’s DISPLAY environment variable to the Container

run container with host network driver with

As soon as you launch a docker container it will open a Mozilla firefox window that is actually running inside a docker container you launched.

Hope you find it interesting thankyou..!!!

--

--