Ishika Mandloi

Jun 1, 2021

2 min read

Gui application in Docker container

We can containerize GUI application in a Docker container that runs in the foreground that is what we’ll see now,

How to Containerise a GUI application in Docker?

Firstly, we’ll create a Dockerfile to build a docker image for firefox:

Create a separate directory for this task (not necessary)

#mkdir dockerGUI

#cd dockerGUI

#vim Dockerfile

FROM centos

RUN yum install -y firefox

CMD [“/usr/bin/firefox”]

Dockerfile

Build the image by using the Dockerfile

#docker build [path] -t [image]

Docker build command

NOW, the main part comes for running container with this image:

To run any GUI application, we need an XServer that we don't have in a container, but we can share the host’s XServer by creating a volume and sharing the host’s display environment variable with the container.

And we need to run the container with the host network driver.

So, while running

#docker run

— net=host

— env=” DISPLAY”

— volume=”$HOME/.Xauthority:/root/.Xauthority:rw” [container-name]

docker run command

And….. firefox is running in docker container!!

Firefox running

Like this, we can run other GUI applications in a docker container.

Thank you all!! I hope this blog will be informative for all.