Running the GUI Application inside Docker Container
Docker is a container technology tool which provides to provising the os in just a few seconds with consumes minimal resources to provision the os. By default docker works on the CLI interface In this article i would like to demonstrate to launch GUI application on the top of docker conatiner.
Normally we have two types of applications which is designed to be run either background or Foreground docker. where GUI application works on Foreground. For launching the GUI application we have to connect the display of the container to the base os. For running the Foreground application always required Xserver which mainly present in the linux system For that base of the docker engine is compulsory to be Linux system.
X server is a program which connects X terminal running applications on the X windows system. where it manages the GUI . X is an architecture-independent system for remote graphical user interfaces and input device capabilities. Each person using a networked terminal has the ability to interact with the display with any type of user input device.
FROM centos:7
RUN yum install firefox xauth -y
RUN yum install libcanberra-gtk2
RUN yum install PackageKit-gtk3-module
CMD ["/usr/bin/firefox"]
Let’s build the image from the above Dockerfile with the following the command after the image created it consist with the firefox application and run the firefox application while launching the conatiner.
docker build -t kallakruparaju/gui-firefox:v1 .
For that by default container didn’t had any xserver For that we have to pass following parameters while launching the container to connect the Xserver with the base os
Running the container with the network host and with the above build image.
--net=host
Passing the envirnoment variable DISPLAY with the value DISPLAY which is passing the base display
-e DISPLAY=$DISPLAY
Mounting the X11 socket volume residing in /tmp/.X11-unix in the base os and mounting to the /tmp/.X11-unix in the container.
-v /tmp/.X11-unix:/tmp/.X11-unix
To launch the container to run the gui application inside the docker container with the following command
docker run -it --net=host -e DISPLAY=$DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unix kallakruparaju/gui-firefox:v1