Graphical User Interface (GUI) inside Docker

Shubham Kumar
4 min readMay 31, 2021


Docker is a platform through which we can host multiple operating systems in less than a minute, in the form of containers through an image, which is a template containing set of instructions for the container to be created

GUI (Graphical User Interface) , as the name indicates, it includes an interactive environment containing visuals consisting of icons, windows. In simple words, we can say that something we can see on screen of our computer and when we click on it then it responds

In this task, I have created an image inside Docker because for opening GUI software inside Docker we need to create our own image with the help of any pre-existing image(centos) inside Docker so that afterwards we can create an operating system over our own image and will be able to run a GUI software in our Operating System. For creating an image, we need to create a Dockerfile because at the time of building our image, it will fetch the code from Dockerfile for creating the image. The need for creation of image is because we cannot run GUI software on any pre-existing images in Docker, because the developers or the community who has created that particular image has not allowed for running a GUI software in the operating system created over their image. So you can check below the steps to create our image and then creating an operating system over that image and running GUI software inside that operating system

First of all, we have to start docker for performing operations related to docker

Create a workspace, here I have created one with the name docker_gui for performing my tasks inside this particular directory

After that, create a Dockerfile with the help of touch command. Dockerfile is needed to create so that we can create our own image with our specifications

Edit the Dockerfile to enter your commands

vim Dockerfile

Here, I have written FROM centos for creating a similar image like centos and after that RUN is used to install the components at the time of building of image so that when we create operating system over our image then that particular operating system would contain pre-installed components which we provided in the RUN command in Dockerfile. “&& \” is used so that whatever is written in the next line will run as a next command after the first one, generally used for providing multiple commands with RUN and “-y” is provided to automatically consider YES as option whenever it prompts during installation

docker build -t image_name:version path

This command is used to build the image with the version name and after that we have to provide the path wherever we have to build the image, here I have used dot to provide the path as current directory

As we can check here that our image skimg has been successfully built

docker run -it --env="DISPLAY" --net=host --name os_name image_name:version

Now, create an operating system over the image with the above command. In this docker run is used for creating and running the operating system and passed env variable with DISPLAY in the container to provide GUI to our operating system and net=host means running our container as the same network as host

After checking the containers, we can find our operating system created over our image

Install jupyter notebook to run as it is a GUI software

Open jupyter notebook with the help of the above command

Finally, jupyter notebook successfully ran in our operating system, launched with the help of mozilla firefox

Thankyou for reading my blog, do provide your valuable feedback in the comments. DM me on LinkedIn for any queries related to this blog 👐