Running GUI application in Docker container


  • Docker installed in OS.

For solving this issue I am showing two methods, the first is manually and the second is Automation, btw I prefer 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 gave 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
  • Great 😅 it works.


  • To remove the warnings, maybe firefox tabs will crash, for solving the issue install some more packages.
yum install PackageKit-gtk3-module libcanberra-gtk2 -y
  • Or one more thing u can do at the time of launching container u can mount x11 server volume.

Automation Method

  • Create one Dockerfile.
  • Build an image from this Dockerfile.
docker build -t IMAGE_NAME(eg-centosgui) .
  • Launch Docker container from this image.
docker run --net=host --env="DISPLAY" --name CONTAINER_NAME centosgui
  • That’s Great it works 😃, As you can see the warning which comes previously, it resolved.



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store