How to run a Graphical UI application or a program on a Docker container?

HarvinderSingh
2 min readJan 28, 2022

Generally docker is used to run servers or some specific purpose containers, but in some exceptional cases where we want to run a gui application like a web browser like firefox, wire-shark or a text editor like gedit or any libre office tool or any thing like that. Then, how do we get the display access for that container?

Before we find out a solution for this, let us understand the functioning of a docker container. Whenever we run a docker container it opens or gives us a terminal for that container if we ask for the terminal using(-it) option with our run command. Now this container is nothing but a normal program like any other programs or applications we run on our OS, but the difference is that it is loaded in different namespace and it feels like we are using or interacting with a new system altogether. So, when we want to attach any volume or drive to our container we just simply mount it using -v option, or when we want to copy a from our system we can do that using environmental variables, similarly when we want to use display for a gui supporting container we use environmental variable DISPLAY.

Now lets move towards our solution…

1. Dockerfile for ur docker image (fire)

> docker build -t fire .

> docker run -it — rm -e DISPLAY=$DISPLAY -v /tmp/.X11-unix/:/tmp/.X11-unix/ — net=host fire

> Now you can try installing and running any of the GUI app like firefox, gedit etc.

firefox running inside a container.

This is how we can use GUI docker containers.

--

--