Run GUI Application inside Docker Container

In this blog, we will launch two GUI applications (Firefox and gedit) inside a docker container.
Pre-requisite:
- Docker installed in the base OS (here, I am using Redhat8 as the base OS)
So, let's start our practical…
Step 1: Pull the Docker container image from DockerHub
Here, I have pulled the CentOS image.
To pull the image, use ‘docker pull <image_name>:version’ command. If the version is not specified, then by default it will pull the latest version of that image.

use the ‘docker images’ command to check the images.

Step 2: Launch Container
Now, we will use the centos image to create a new container.
Use Command: ‘docker run -it -e DISPLAY=$DISPLAY -v /tmp/.X11-unix/:/tmp/.X11-unix — name <container_name> centos’
Here, we have added an environmental variable $DISPLAY for the X11 display and mounted a volume /tmp/.X11-unix/:/tmp/.X11-unix for the X11 Unix socket as the X server is responsible for GUI.

Step 3: Launch the GUI application in the container
- Launch Gedit
First, check whether the application/software is present or not.

As the gedit software is not installed inside the container so we will first install gedit using the yum command.

Now, run gedit.

Successfully launched the gedit software.
- Launch firefox
First, check whether the application/software is present or not.

Install firefox using the yum command.

Now, run firefox.

Successfully launched both the GUI-based application inside a docker container.
😊Thank you for Reading😊