How to run GUI tools in Docker?

Many of you might have used docker and somewhere you might have thought of, having GUI to docker would be so fun to work. It will be exactly like a VM booting up in no time. So, let’s do this activity and I will show you how you can run GUI applications in a docker container. We will build this using a dockerfile.

What all packages we need to build this image?

  1. libcanberra-gtk2: Libcanberra is an implementation of the XDG Sound Theme and Name Specifications, for generating event sounds on free desktops, such as GNOME. It comes with several backends (ALSA, PulseAudio, OSS, GStreamer, null) and is designed to be portable.
  2. packagekit-gtk3-module: PackageKit is a system designed to make installing and updating software on your computer easier. The primary design goal is to unify all the software graphical tools used in different distributions and use some of the latest technology like PolicyKit.
  3. gedit: Linux text editor.
  4. firefox: Browser
  5. Python36: To execute python code.
  6. centos:latest: Image on which we will set up this feature.

Dockerfile:

Here, — rm is used for removing the intermediate containers build after a successful build.

How to use this image?

Here, we need to set the DISPLAY environmental variable to our host system using the option -e. We need to mount the X11 socket, this will actually help us to take the output of GUI to our host system. We will be using the host network for this container, therefore we used — net option.

You will see on your host that we have launched the firefox GUI application on a docker container. Similarly, we can execute the text editor also which we have installed.

Dockerfie code:

FROM centos:latest
RUN yum install libcanberra-gtk2 -y
RUN yum install PackageKit-gtk3-module -y
RUN yum install python36 -y
RUN yum install firefox -y
RUN yum install gedit -y

--

--

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
Shubhambhalala

C|EH | Cybersecurity researcher | MLOps | Hybrid Multi Cloud | Devops assembly line | Openshift | AWS EKS | Docker