GUI container in Docker

Hello Folks!

I am writing this blog in response to the task given to us which contain various steps:

🔅 Launch a container on docker in GUI mode

🔅 Run any GUI software on the container

I am doing this on the top of a virtual machine. First we will configure the docker file to use it for the installation of docker. Create a docker.repo file in /etc/yum.repos.d with the following code.




After the successful configuration of the docker file, it can be downloaded with the command.

Yum install docker-ce — nobest

When the docker is successfully installed we need to restart it and it can be restarted with the help of systemctl start docker, it will start the docker daemon.

We can check the number of docker images with the command docker image with the command as docker images which shows the active one and docker images -a which shows all the docker images uploaded till time.

We can all see the list of docker containers with command docker container list and all the active docker containers can be checked with the command docker ps and docker ps -a which shows all the docker containers created in its lifetime.

We can pull docker images (here images refer to the iso images of the os) with the command docker pull centos:latest. It pulls the docker image by referring to the config file.

In this task, we first created a docker run [options] [container_name] [image_name]. In our case it is

docker run -it ost2 centos:latest

One can restart the existing docker container with the command docker start ost2 which starts the container docker attach ost2 which makes a user go inside that container.

Here i stands for interactive and t stands for terminal. As soon as we run this it will create a docker container with the os name as ost2 and then we install python3 which will be installed by yum install python3 which shows some error, and can be resolved with the help of commands.

firewall-cmd — zone=public — add-masquerade — permanent

firewall-cmd — zone=public — add-port=80/tcp

firewall-cmd — zone=public — add-port=443/tcp

firewall-cmd — reload

systemctl restart docker

After successfully installing it then if we install jupyter notebook with the command pip3 install jupyter but when we launch jupyter notebook it will show an error, for that reason we will add — allow-root and it will install but it won’t launch because jupyter notebook needs firefox which is a GUI software. For this we will follow a different alternative.

In the alternative way we will first create a Docker file which is a concept to create Docker images. It has three keywords FROM, RUN and CMD the FROM specifies that on the top of centos latest version we will build our image and run command specifies the commands that needs to be executed and CMD specifies those commands which needs to be run as soon as the OS launches.

The next step is the building of the image which is done by the command docker build -t image_name:tag . Here the . refers that the Dockerfile is created where the docker build is run.

The image is successfully built now using that image we are going to launch a container with the command.

docker run -it — name task — env=”DISPLAY” — net=host gui:latest

After typing that command, the jupyter notebook successfully started and it is workable.

Thank you for the read!!