Made using Canva

GUI Applications in Docker ๐Ÿ’ป

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.

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.

Dockerfile

Create a directory and save this Dockerfile there.

mkdir docker_gui/
cd docker_gui/

โ— 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.

Thatโ€™s all for now. Thank You !! ๐Ÿ˜ŠโœŒ

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Rahul Sil

I am a tech enthusiasts. I love exploring new technologies and creating stuff out of them !! โœŒ