Running GUI Applications inside Docker Container.

Yagyandatta Murmu
3 min readJun 1, 2021
Running GUI Applications in Docker — Firefox, Nautilus File Manger. |  LaptrinhX
firefox in docker

This article will see how we can run the GUI applications inside the docker container. Before we start first, let’s discuss the basic terminologies that will help us understand the article better.

To know more about Docker, you can refer to my previous blog. (docker)

What is Dockerfile?

A Dockerfile is a text document or script that contains all the commands a user could call on the command line to assemble an image. They are used for organizing things and greatly help with deployments by simplifying the process start-to-finish.

Why do we need the GUI application to be run inside the docker container?

  • Very quick and easy to launch.
  • Whenever you are on the GUI program, it’s running its own process inside a container.
  • Nothing to do with your system or with your process.

Prerequisites:

✔ Docker must be installed on your system.

You can see the installation from my previous Article ( Docker-installation).

Steps to create and Launch Docker Container with Dockerfile.

  1. First, we need to start the docker service, start the docker service using this command:
systemctl start docker

2. Check the status of the docker service:

systemctl status docker

3. You can enable your docker service permanently by this command

systemctl enable docker

We need an OS image to run containers, we can get images from the docker hub.

4. To download an image from the docker hub we can use this command:

docker pull [OPTIONS] [imageName]:[version]
I'm using centos latest version for this practical,
>> docker pull centos:latest

5. Create a Dockerfile on your main system. (I'm using RedHat 8 as my base os)

>> vim Dockerfile
FROM centos:latest
RUN yum install firefox python3 -y
CMD pip3 install jupyter

6. Now let’s build a Docker Image from Dockerfile,

docker build -tag [image_name:version] [Dockerfile path]>> docker build -tag .# Here we are using “docker build” command to build the image & to  give the image a name/tag we are using “-t” option.
# I'm using "." at end of above commmand, because I'm inside where my Dockerfile is.

You can verify the image here with this command.

>> docker images

7. Now you will see your image is ready. So again to create the container from this image you can run this command.

docker run -it --name=[name] --network=host --env="DISPLAY" [image:version]>> docker run -it --name=dockerguiapp --network=host --env="DISPLAY" guimage:v1 where, 
run :- this keyword will launch the container
-it :- this gives interactive terminal
--name :- use to set the name the name of container
--network=host :- use to launch the container with host network
--env="DISPLAY":- This is use to share the display of the host to the container
# RUN and CMD are both Dockerfile instructions. RUN lets you execute commands inside of your Docker image.CMD lets you define a default command to run when your container starts.

8. After launching the container run jupyter notebook,

jupyter notebook --allow-root

Well Done, we have launched Jupyter Notebook Successfully on Docker Container.

GitHub URL: https://github.com/yagyandatta/GUI-app-in-Docker

Happy Coding !

--

--

Yagyandatta Murmu

Devops || MlOps || Flutter || Web Development || PYTHON || Data Science || AWS cloud || GCP || Azure