Launching GUI Application on top of Docker Container

Aditya Pande
2 min readJun 1, 2021

--

Task Description:-

  • > GUI container on the Docker

🔅 Launch a container on docker in GUI mode

🔅 Run any GUI software on the container

In this task, we will see how we can launch any GUI Application on top of Docker Container. In this article, I will show you how we can launch Firefox and Jupyter Notebook on top of Docker Container. Whenever we launch any docker container, then it by default always launch in CLI mode and don’t give us GUI as it is disabled and due to this we can’t run any GUI commands in docker container as it is not a good practice.

Although, if you want to launch any GUI application in docker, then by doing some settings we can achieve it. But, for this we first need to have that GUI software installed in container. So, we can either do this manually using “yum” command and create image of this container using command->

docker commit <container_name> <image_name>:<tag>

We can also put all commands inside one file and when we execute this file it will create one image for us which will have all GUI softwares pre-installed and this file is known as “Dockerfile”. We have to create file using same name. In this file, I have used following keywords:-

i) FROM:- This keyword is used to specify the base image which we are going to customize and create a new customized image.

ii) RUN:- This keyword is used to run any command for installing softwares, etc. and is executed at built time.

For creating image, use command->

docker build -t <image_name> .

After successfully creating this image, we will launch container using command->

docker run -it --name=<cont_name> --net=host --env= “DISPLAY” <img_name>

In above command,--net option is used to share the host network of BaseOS which in my case is RHEL8 with the container we are launching and --env option is used to set the “DISPLAY” as environmental variable so that GUI application will be able to launch and specify the customized image name you built as the last. This will give you bash prompt of container which will look like BaseOS. But you can test it by running some of commands that are not installed on container. For e.g ifconfig.

Now, after launching container run GUI commands like, firefox and jupyter notebook. For Jupyter Notebook, root user access is disabled, that’s why we have to provide one option called “--allow-root” with it.

jupyter notebook --allow-root

Refer below video for following complete process:-

--

--