Is It Possible To Run GUI Based Applications Inside A Container?

Today, the entire IT world is utilizing the power of a container to do some amazing stuff. No doubt, containerization has turned out to be a boon for the tech market. (Here, I am particularly talking about the Docker)

  • Most of the times you have heard that people generally use containers for Enterprise Server Applications. But standing alone from the crowd, is it possible to use containers for a Desktop environment?
  • Did you know, that the Docker container has a huge scope when it comes to impacting the Development Environment?
    The best part about Docker is that — using docker, you can containerize almost every single technology you work on. From launching the environment to deploying some real servers on it — just a second away!
  • Now, the most important question — How is it possible to run a GUI based app inside Docker? Here is the answer:

If we talk about the running nature of any application, you can find only two of them:

  • Applications that run in the background such as webservers.
  • Applications that run in the foreground (generally, GUI based) such as a web browser.

In this blog, I am going to show you how to run this second type of application inside a docker container.

Let’s first try to run a GUI application (say, Firefox) inside a docker container.

To launch a docker container with ‘centos’ as its base image:

docker run -it --name gui centos

After launching and getting inside the container, let’s install firefox:

yum install firefox -y
  • Yum is the package manager of Centos. And you do not need to configure inside the docker because the centos image comes with pre-configured yum.

After installing Firefox, if you try to launch firefox using ‘/usr/bin/firefox’ command, it will show the above error:

The error says that a “DISPLAY” environment was not found. So, here are the steps we are going to perform in order to solve the error:

  • Create a Docker image that has firefox installed
  • Launching container by providing it with a DISPLAY variable. Also, we will launch it in a ‘host’ network. Host network by default exposes a container so that it can be directly used from the base OS.

Let’s try to carry out the same:

FROM centos
RUN yum install firefox -y
CMD ["/usr/bin/firefox"]
docker build -t docker_gui .

I have created the same:

docker run -it --env="DISPLAY" --net=host --name firefox docker_gui

And the GUI application (firefox) has been launched inside the container:

That was all as of now. I hope you liked the above blog.

  • This practical was just a small demonstration of the magical stuff that can be done using Docker.
    Docker has an amazing scope in the IT world. Top MNCs are leveraging the benefits of Docker to a huge extent.
  • I hope you got to learn something unique from the above article. I am a DevOps Enthusiast and I keep on writing similar exciting blogs on trending technologies.
  • You can check out my LinkedIn profile mentioned below. Feel free to DM me in case of any queries/suggestion and follow me on Medium.

I am an active learner who likes to challenge every problem with a can-do mindset in order to make any idea a reality.