Skip to content
Related Articles

Related Articles

Improve Article

How to Run GUI Based Applications inside Docker?

  • Last Updated : 17 Aug, 2021

A Docker Container is an isolated application platform that contains everything needed to run to an application built from one or more images.

Docker is an Open Source project that provides an open platform to run any number of applications inside a container according to your requirements and you can also save that environment for future use also as an image of a lightweight container.

We can easily run the most common GUI applications without getting into trouble inside a Docker Container. To run GUI Applications inside a Docker Container only needs to follow few very simple steps which are provided below. 

Implementation:

Follow the below steps to run a GUI application inside Docker:

Step 1: Install and Start Docker and check the status and restart the service. The Systemctl commands are used to manage system services.



systemctl start docker            // to start the docker service.
systemctl status docker           // to check the status .
systemctl restart docker          // to restart the service.

Step 2: Now pull an image from DockerHub to base OS Rhel and launch a container and install python3 inside the container.

docker run -it — name os_name centos:latest         

To run docker container,(-it means interactive terminal, “os_name” you can give according to you easy to remember and “centos: latest” will give you container of centos with the latest version of centos.

yum install python3                             

To install python3 inside the docker container you can choose any version of python, “yum” is used for installing, deleting, and querying software packages.

Step 3: Install any no. of GUI Application inside container here I am going to install firefox, jupyter & gedit.

yum install firefox -y             // to install firefox 
pip3 install jupyter               // to install jupyter
yum install gedit -y               // to install gedit

Step 4: Now create an image from the previously launched container and then launch a container of this newly created image(Inside baseOS).

exit                                                // to exit from the container ,
                 
docker commit os_name image_name:version          // Now you are in base OS type the
                                                  // following given below command.

To create an image from your running container,”os_name” is your own os you are going to create so give it a name according to you, “image_name” is the image of your own OS that you are going to create so here also give according to you and “version” suppose it’s your first image so give version as v1 or whatever you want to give. The “commit” command is used to create an image from your running container.

docker run -it --name container_name --env=”Display” -- net=host image_name:version    

To run a new docker container from your created os image in which you already install some GUI applications and env displays the environment that it received from its parent(base os), and set image name and version as you mentioned in the previous command. This is your new docker container so give a new name to this os.

 Step 5: Now here you can check by using the given commands:

firefox                            // to run firefox inside the docker
jupyter notebook                  // to run jupyter inside the docker
gedit                             // to run gedit inside the docker
exit                              // to exit from the container

My Personal Notes arrow_drop_up
Recommended Articles
Page :