Running GUI application in Docker Container

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).
  • Start docker container normally.
  • 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.

Automation Method

  • Create one Dockerfile.
  • Build an image from the DockerFile.
  • Launch Docker container from the image.

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

Lifelong learning technologies