Is it Possible to Run GUI Based Applications inside Docker Container?

Sumayya Khatoon
4 min readApr 10, 2021

--

Hello Folks! This Blog gives an Answer to the question “Is it Possible to run GUI Based Applications inside a Docker Container? So, guys get going…

Containerization has become an efficient way of boosting productivity in IT development processes. As the market keeps growing, people want explore the biggest Docker benefits and they want to know more about this valuable tool. Today the entire IT world is utilizing the power of Containers. Using containers developers can create predictable environments that are isolated from other apps. Regardless of where the app is deployed, everything remains consistent and this leads to massive productivity: less time debugging, and more time launching fresh features and functionality for users.

What is Docker?

Docker is a tool designed to make it easier to create, deploy, and run applications using containers. Docker run over the Base Operating System and it mostly supports non GUI application i.e. CLI

But now the question arises “Is it Possible to Run GUI Application inside a Docker Container?”. The answer is a big YES…

  • Using Docker you can Launch every single technology just in a span of one second.

But now again the question arises “How we can run a GUI Application inside a Docker Container?” So, let’s implement the practical for the same.

Is there any Pre-requisites?

  • Yes, Docker to be installed.

We can launch GUI App inside Docker Container in two ways:

  • Manually
  • Automation using Dockerfile.

So, first try to implement the practical manually →

Step 1: Pulling the Docker Image from Docker Public Repo.

  docker pull <name_of_image>

Example:

docker pull centos

Step 2: Launching Docker Container.

Below is the command for launching the Container:

  docker run -it --net=host --name <name_of_os> <image_name>  Example:

docker run -it --net=host --name os1 centos
Container launched successfully

Step 3: Installing GUI Application.

Here I’m installing Firefox as GUI Application.

As yum is pre-configured you can use yum command to install firefox

  yum install firefox -y
GUI App Installed Successfully

Step 4: Start the Firefox

  firefox
Error

It gave an error because it needs one environment variable for Display. So, while launching container we need to specify an environment variable for display.

Step 4: Launching Container with environment variable.

Now launch the container with environment variable DISPLAY and again install Firefox inside the container.

GUI application installed successfully!

Now, start the Firefox…

Firefox started Successfully!!
GUI Application launched successfully!!

Voila!! Now, we’re are also able to run GUI App inside the Docker Container😊

Now , Let’s try to Automate each and every step using Dockerfile →

Step 1: Build a Dockerfile that has FireFox installed.

  docker build -t <image_name> <path>  Example:  docker build -t  sumayyadocker/firefox  .
Docker Image built Successfully!!

Step 2: Launch Container using the Built Image.

 docker run -it --net=host  --env="DISPLAY"  --name <name_of_os>  <image_name> Example:

docker run -it --net=host --env="DISPLAY" --name guios sumayyadocker/firefox
Container Launched successfully

After running the above command we landed in the docker container with the GUI Application.

GUI App ran successfully!!

Voila!! Now, we’re are also able to run GUI App inside the Docker Container😊

Hope you find this Blog easy and Interesting!

Do like, Comment and Connect me.

Thank You!!

Thank you for Reading!!

--

--

Sumayya Khatoon
Sumayya Khatoon

Written by Sumayya Khatoon

Machine Learning || Deep Learning || Kubernetes|| Docker || AWS || Jenkins || Ansible(RH294) || Python || Linux(RHEL8 )

No responses yet