📙Running a GUI container on the Docker

AYUSH BAJPAI
4 min readJun 1, 2021

Welcome friends, this is task 2 of my summer training at Linux world.So, In this task, I am going to run a GUI container on the docker. so let’ start.

🧐🧐steps to be followed in this task:

🔅 Launch a container on docker in GUI mode

🔅 Run any GUI software on the container

Pre-requisites: docker should be installed on your base operating system, in my case, I am taking Rhel 8 operating system.

👉Step 1:

First of all, we should check our docker is installed in the system or not. To check docker is installed or not,use the following command:

docker  -- version

As we can see docker is installed successfully in our system. so now move further

👉Step 2: Start the docker service

To start the docker service use the below command:

systemctl start docker

to check docker service started or not use below command:

systemctl status docker

Docker service started successfully.

👉Step 3: Pull the Centos Image

now as our service is started successfully now we have to pull the centos image from the docker hub.

command to pull centos image is given below:

docker pull centos:latest

docker images command tells us the no. of images present in our operating system. As we see our centos image is successfully pulled.

👉👉Step 4:Creating a container

The next step is to create a docker container. To create a container use the below command:

docker run -it --name ayush6 centos:latest

As we see our container is successfully launched. and its command prompt is now showing.

now we install firefox in the launched container using:

yum install firefox

now when we run firefox in the conatiner it is showing error:

as we see it shows error:

📌📌NO DISPLAY ENVIRONMENT SPECIFIED.

so we have to run the container with Xserver to resolve this issue .

📌What is X server ?

For a GUI Application to run inside a container , we need to have an XServer which is available as part of every Linux Desktop Environment, But within a Container, we don’t have any XServer — so we will

  • share the Host’s XServer with the Container by creating a volume
  • --volume="$HOME/.Xauthority:/root/.Xauthority:rw"
  • share the Host’s DISPLAY environment variable to the Container
  • --env="DISPLAY"
  • run container with host network driver with
  • --net=host

so now we will run a new container with all the above options:

docker run -it — name ayush8 — net=host — env=”DISPLAY” — volume=”$HOME/ .Xauthority:/root/.Xauthority:rw” centos:latest

now we will again install firefox in this new container.

yum install firefox

after installing firefox now we will run our firefox command to see the gui application running inside the container:

🎯🎯so as our firefox (gui application) runs successfully inside the container. hence task completed successfully.

🤜👍thanks for reading. meet you in the next task.

--

--

AYUSH BAJPAI
0 Followers

ansible learner,coding enthusiast,learning new technology