Running GUI Applications on Docker with Docker Host’s Screen
Hello Technical Enthusiasts ! Hope you all are doing great. There’s one thing I wanna ask you, do you know that we can run GUI applications like our music player, web browsers, jupyter notebook and almost every application as such on Docker Interface 🤔?.
Well the answer is yes and But How Exactly?
For that we have to use GUI Screen of our typical SSH client or we may make use of Graphical Screen of our Docker Host and that’s what we are going to do 😉 and so let’s get started on how are we gonna make it.
Approach
In order to let the docker host share its graphical screen with the docker containers, we have to share the X11 server socket file with the launched container OS.
X11 Server -X11 is a network protocol designed for Unix and similar operating systems to enable remote graphical access to applications
So basically since X11 server is the one responsible for Sharing the graphical inputs for CPU to the Display Console.
Once the Socket file has been shared, we have to tell our docker container that a X11 server is currently running somewhere in the same system. This can be achieved by sharing the DISPLAY environment variable with docker container at the time of launch.
Starting with the Setup
- Checking whether Docker is running fine or not
I would be explaining everything step by step .So starting it by checking the status of docker running or not . This can be done using below command👇
systemctl status docker
2. Pulling the centos image
Once we are sure that the docker is running fine , so we can now pull the centos image that we are going to use for launching a container.
3. Launching the docker container with proper options
As discussed earlier , we will be sharing the socket file /tmp/.X11-unix/ with the container by mounting the file onto the same location.
Also we will be sharing the DISPLAY environment value whose socket value is by default :0 in most of the Linux distros.
And here we go , the system is ready to work with graphical applications that would basically invoke the Graphical Screen of Docker Host 👍.
Testing
Lets see whether we are able to use Firefox or not and for that purpose , I’m going to install the Firefox software. Since I’m in centos , so I can install Firefox by making use of yum command.
After the successful installation of Firefox , you would be able to see a Complete notice at the end.
Now to start Firefox , you may use the firefox command and see whether the command is running or not.
Note: You might get some Warning like Failed to load module but that’s okay, its related to system security due to GUI Screen Sharing and D-Bus connections.
If everything worked Great , then you will get the output like below which is a proof to the fact that Firefox is running on Container🙂.
On the Right side of Mozilla Firefox , you can see the container ID of the docker container. So that’s all I wanted to share today.
Hope to see you again some day in some new article, hope you liked it. Thankyou for your patience listening till the end 😉.