GUI container on the Docker

Ritik Bobade
4 min readMar 20, 2021

We will be performing a task that will be launching the docker container in Graphical User interface mode.

Task Description 📄

🔅 Launch a container on docker in GUI mode

🔅 Run any GUI software on the container

In order to launch a Docker container we will be requiring a OS ,for this task we will be using a RHEL8 (Red Hat Enterprise Linux 8) OS with docker installed in it.

Firstly we will check the status of docker whether docker is running on the OS or not. We can check this by command

systemctl status docker

As we can see docker is running in our system and we can launch the docker container , for launching a container we need a image we will be using a centos image for launching the container in order to identify our container easily we can give out container a name we will be giving name as “task” to our container To run our docker container with specific name we run the command

docker run -it –name=task centos

Now our container is launched we can check the GUI support by running a software in our container, we will run firefox in the container.

Lets first check whether firefox is installed or not we can check by command

rpm -q firefox

As we can see firefox is not installed on our container we need to install it we can install it by running command

yum install firefox

Now as we have installed firefox lets run it by running simple command

firefox

So there is no GUI support in our container as we can clearly see so lets enable the GUI support by launching a new container altogether.

Firstly we will create a new workspace named “task ” by running command

mkdir task

Now enter the workspace by command

cd task

Now we will create our own image with set of rules and use centos image as reference as it not come with GUI support initially we will write some rules or process to be implemented at start-up of the container.

To create our image/docker file we will run command

vim Dockerfile

Now inside the docker file we need to specifies which things to be implemented on start-up

To take the reference image as centos we will write

FROM centos:latest

To have the desired software we will write

RUN yum install firefox -y

To run firefox we will write

CMD /usr/bin/firefox

And then save the file and exit.

Now we have to build our image that we just created with a name I am giving name as mygui2 by running command

docker build -t mygui2:v1 .

Now we are all set to launch our new container with GUI support we by running command

docker run -it — name=task26 –-env=”DISPLAY” — net=host mygui2:v2

In the above command we can see that env variable is set to “Display” this is the main argument that will give GUI support to our docker container.

We can see after launching the new container Firefox has been opened in the GUI mode and that shows the GUI support to our docker container.

--

--