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?
- 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.
- 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.
- gedit: Linux text editor.
- firefox: Browser
- Python36: To execute python code.
- centos:latest: Image on which we will set up this feature.
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.
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