Most of us know that Docker is a containerization tool that helps us in provisioning an OS within seconds.
Well if you did not know about that, you know it now !! 😉
It basically creates a process in the base system which is treated as a new operating system.
In most of the use cases in the industry utilizing the container technology we use the CLI only and Docker gives us the CLI of a container only and not the GUI.
But it might be sometimes needed that we want to launch a graphical application inside a docker container and that is by default not possible. We need to pass certain variables during the runtime of the container so that the container can launch certain GUI applications.
🚩 In this blog, I am going to show you how you can enable and launch a GUI application inside a docker container. ✨🤩
I will be using 𝗥𝗲𝗱𝗛𝗮𝘁 𝗘𝗻𝘁𝗲𝗿𝗽𝗿𝗶𝘀𝗲 𝗟𝗶𝗻𝘂𝘅 ( 𝗥𝗛𝗘𝗟 ) 𝟴 operating system as the Docker host that is the base system.
📍 You need to have docker configured in the system. You can refer to the below-mentioned blog where I have explained how to configure docker.
⚜ 𝗠𝗮𝗰𝗵𝗶𝗻𝗲 𝗟𝗲𝗮𝗿𝗻𝗶𝗻𝗴 𝘂𝘀𝗶𝗻𝗴 𝗖𝗼𝗻𝘁𝗮𝗶𝗻𝗲𝗿𝗶𝘇𝗮𝘁𝗶𝗼𝗻…
Technology was not what it was many years ago. It has changed and is evolving continuously. 💻
After you have configured docker in your system, proceed with the following steps. ✌
I have created a basic Dockerfile that will have the GUI applications software already installed.
You can find the Dockerfile in the following Github repo.
Create a directory and save this Dockerfile there.
❗ The name of the file should be “Dockerfile” only. ❗
After you have created the Dockerfile using your favourite text editor, now it's time to create the docker image.
docker build -t docker_gui:v1.0 .
Make sure to run this command in the location where the Dockerfile is present.
I have already created the image and uploaded it to Docker Hub. You can pull that image also.
Docker Hub Link — https://hub.docker.com/r/rahulsil/docker_gui
After we have all the above things set up, let us move onto the main part of launching a GUI application inside a Docker container.✨
docker run -it --name guios--net=host --env="DISPLAY" --volume="$HOME/.Xauthority:/root/.Xauthority:rw" rahulsil/docker_gui:v1.0
Run the above command to launch a new container.
Now the command is quite messy, right? Let us understand it properly:
- run:- is used to start our container
- -it:- this keyword provides us with an interactive terminal
- - -name:- used to set the name of the container
- guios:- it is the name of the container, anything could be given.
- - -net=host:- use to launch the container with the host network.
- - -env=”Display”:- This is used to share the display of the host to the container
- - -volume=”$HOME/.Xauthority:/root/.Xauthority:rw”:- This is used to share the host X server with the container by creating volume.
As you can see as we launched the container and executed the firefox command the firefox browser opened and shows the centos home page as the container is created from Centos image.
This way we have successfully completed the task of launching a GUI application inside a docker container. 😍✨
I will soon come up with a blog where I will be explaining the basics of docker and the commnds of docker, dockerfile that I have used here. Stay tuned for that !!
I hope you liked this article.💖
Would definitely like to hear your views on this and feedbacks so that I can improve on those points in future articles. 🙌 Comment your views below.
You can also check my LinkedIn profile and connect with me.
Follow me on medium as I will come up with articles on various technologies like Cloud Computing, DevOps, Automation, and their integration.
Rahul Sil - Certified Kubernetes Application Developer ( CKAD ) - ARTH - The School of Technologies…
Hello everyone, I am Rahul Sil, a technology enthusiast. I love playing with technology and to try out various…
That’s all for now. Thank You !! 😊✌