We can’t run a GUI application on top of docker container by default. Because container does not have xserver which is required to run a GUI application on linux.
So here we will see how we can launch a GUI container on top of docker.
What is Xserver ?
An X server is a program in the X Window System that runs on local machines (i.e., the computers used directly by users) and handles all access to the graphics cards, display screens and input devices (typically a keyboard and mouse) on those computers.
Steps to launch a gui container on docker
1) Start the docker service as:-
systemctl start docker
2) Now pull a Docker image from Docker hub as:-
docker pull centos:latest
3) Now launch a docker container as:-
docker run -it --env= “Display” --name gui_os --net=host — volume = “$HOME/.Xauthority:/root/.Xauthority:rw” centos:latest
Here,
- --env= “DISPLAY” will share the docker host’s DISPLAY environment variable to the docker container.
2. — volume = “$HOME/.Xauthority:/root/.Xauthority:rw” will share the docker host’s Xserver with the docker container by creating a volume.
3. --net=host will run the docker container with host network.
4) Now we will install the GUI application in the container. In our case we will install firefox as:-
yum install firefox -y
Now launch the firefox as :-
firefox
It will launch the GUI application (firefox) for us.
Now, we will launch another GUI application jupyter--notebook.
For this we have to first install the python and jupyter inside our container as :-
yum install python3 -y
pip3 install jupyter
Now we will launch jupyter as: —
jupyter notebook --allow-root
It will launch jupyter notebook for us.
Now our task is done. Thankyou