Running GUI Applications in Docker Container.

Lalita Rajpoot
3 min readOct 30, 2021

Container:-

Containers are a solution to the problem of how to get software to run reliably when moved from one computing environment to another

What is Docker?

  1. Docker is a tool designed to make it easier to create, deploy, and run applications by using containers.
  2. Docker containers are lightweight alternatives to Virtual Machine and it uses the host OS.
  3. We don’t have to pre-allocate any RAM in containers.
  4. Dockerfile builds a Docker image and that image contains all the project’s code.
  5. We can run that image to create as many docker containers as we want.
  6. Then the image can be uploaded on Dokcer Hub, from Dokcer hub any one can pull the image and build a container.

Now, let’s see how to launch GUI application in docker:

Step — 1: Start the Docker Service

To start docker in our system we use below command

systemctl start docker
start docker

Now, we will check status of Docker using command:

systemctl status docker
docker status

Step — 2: Pull the Centos Image from DockerHub

We should make a Docker Container using the Image that is already available in DockerHub Repository.

To pull any image from DockerHub we use command:

docker pull Imagename:version

Here, we are pulling centos image from DockerHub ,

use command:-

docker pull centos:latest 
pulled centos image

Step — 3: Creating Dockerfile

To Create a customized docker image:

Dockerfile:

A Dockerfile is a text document that contains all the commands a user could call on the command line to assemble an image. Using docker build users can create an automated build that executes several command-line instructions in succession. This Dockerfile will have the required packages and also, have directory created inside it to where we would mount our local folder which is containing our code.

Dokcerfile data

Step — 4: Build the Docker image using Dockerfile

To build docker image using Dockerfile we use command:

docker build -t container_image .docker build -t dockergui .
  • -t : Tag option helps us to tag the image with a proper name.
  • container_image : In this case, the container image is “dockergui”.
  • Dot operator: Indicates that the Dockerfile is present in the current folder.
built image using dockerfile

Step — 5: Launch the GUI Container:

We will use the docker run command to launch the container.

docker run --env="DISPLAY" --net=host --name=firefox containe_imagenamedocker run --env="DISPLAY" --net=host --name=firefox dockergui

We specify the env=”DISPLAY” because we want the container to use the DISPLAY variable from the Host OS.

The — net=host option is used to make the programs inside the Docker container look like they are running on the host itself, from the perspective of the network.

GUI in Docker container

Now, Successfully GUI is running in our Docker Container.

It’s so simple way.

Thanks for read my article……….. :)

--

--

Lalita Rajpoot
Lalita Rajpoot

No responses yet