GUI Application via Docker

Mahek Batra
3 min readMay 31, 2021

Tired of using Docker’s CLI why not use GUI . How?

Let’s see step by step method of running GUI apps in a docker container.

Prerequisite: You should have docker installed in our Base OS.

In our example we have run firefox in a docker container.

Docker is already installed in my RHEL8.

To check whether it is installed or not I have used the command

• docker info

Now let’s have a look on the running containers by docker ps command.It’s an empty list.

Now there are two options either you can create your own image or you can use the any one of the image from docker hub.

• docker pull centos

If you want to create your own image so first you have to create a ‘Dockerfile'

• vim Dockerfile

Write this lines in the file for creating an customized image of name firefox.

  • FROM centos
  • RUN yum install firefox -y
  • CMD [“usr/bin/firefox”]

RUN and CMD are both Dockerfile instructions.

RUN lets you execute commands inside of your Docker image. These commands get executed once at build time and get written into your Docker image as a new layer.

CMD lets you define a default command to run when your container starts.

Now build the image by using the command.This command used the Dockerfile to build a new container image

• docker build -t firefox .

Now you can seacrh the image by using the command.Grep is a Linux / Unix command-line tool used to search for a string of characters in a specified file.

• docker images | grep firefox

Now we have to run this container by passing an environment variable as a DISPLAY and and network as a host .

• docker run -it — name=OS1 — net=host — env=’DISPLAY’ firefox

This DISPLAY variable is used to indicate to graphical applications where to display the actual graphical user interface,

The Docker option — net=host configures the Docker container to share its network stack with the host

And here you go!!!

We have successfully launched the firefox on the docker container.

Thank you for reading!!!

--

--

Mahek Batra

BE 3rd year || Information Technology|| Dedicated|| Passionate||