Launching A Container With GUI Inside Docker

Dhruval Mayavanshi
2 min readMay 30, 2021

Hello folks,

In this blog, we are going to see how to launch the container with GUI in docker.

What usually happens when we launch a new container in Docker. We need some image for the container. And this image by default launch with only CLI inside the container. So, in this OS if we launch any application of GUI it fails.

So for overcoming this here’s a small tip.

Let’s follow step by step process.

Step 1 - Launch the Docker and Pull the image from the DockerHub.

In this case, I am using centos image.

docker pull centos

for checking the available images on your system

docker images

Step 2 - Now launch the container

This command will launch docker with interactive terminal and set DISPLAY environmental variable, which can able to launch GUI in the container and allows network access of the host.

docker run -it — env=”DISPLAY” — net=host centos

Step 3 - Now install any GUI program inside the container

Here I am installing firefox using the yum command

yum install firefox

Step 4 - Now try to launch the firefox

firefox

And when you press the enter,

your Firefox is launched.

This is how you can launch the container with GUI in docker and use any GUI program inside the container.

I hope you liked it!

Happy Learning, Meet soon!!

--

--

Dhruval Mayavanshi

Future Engineer | Learning Design, Animation and Technologies