Running GUI application in Docker Container

Arnab Saha
2 min readMay 29, 2021

Prerequisites

  • Docker installed in OS.

For solving this issue I can show two methods, the first is manual and the second is Automation.

First Method(Manual)

  • Pull one image(eg-centos).
docker pull centos
  • Start docker container normally.
docker run --net=host -it --name c1 centos
  • Install one GUI application for eg, I am installing firefox.
  • After the installation let’s start firefox.
  • Oops, it gives an error, now let understand the error, it needs one env variable for x11 Display, so we need to define $DISPLAY.
  • Now launch one more container with env $DISPLAY, and install firefox.
docker run -it --net=host --env="DISPLAY" centos

Automation Method

  • Create one Dockerfile.
  • Build an image from the DockerFile.
  • Launch Docker container from the image.
docker run --net=host --env="DISPLAY" --name CONTAINER_NAME centosgui

There is one more way to make it possible.

We know that X11 server is responsible for GUI environment. So by enabling it we can run GUI application inside Docker.

The command to set X server socket is -v /tmp/.X11-unix/:/tmp/.X11-unix

echo $DISPLAY sets the display of container.

The display is set so now we can install firefox and run it.

If you find it riveting please upvote it.

Connect with me on LinkedIn | GitHub

--

--