Open In App

How to Run GUI Based Applications inside Docker?

Last Updated : 04 Jan, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

A Docker Container is an isolated application platform that contains everything needed to run an application built from one or more images. Docker is an Open Source project that provides an open platform to run any number of applications inside a container according to your requirements and you can also save that environment for future use also as an image of a lightweight container.

We can easily run the most common GUI applications without getting into trouble inside a Docker Container. To run GUI Applications inside a Docker Container only need to follow a few very simple steps which are provided below. 

What is Docker?

Docker is container platform that helps in packaging an application with all its dependencies into a single entity. It facilitates the developers to build, ship and run the applications in any system that supports docker. It helps in simplifying the process of deployment and management of the applications by creating abstraction to the infrastructure details and making easy of container creation, deployment. It streamlines the development to production workflow on improving the scalability and reliability of the application.

What Are Docker GUI Containers?

Docker GUI Containers are the docker containers that includes the graphical user interface (GUI) components facilitating users to run and interact wwith GUI-based applications within isolated environments. These containers comes with encapsulating both the applciation and its graphical interface depedencies providing consistent deployment across the various platforms.
These containers streamlines the development, testing and deployment of GUI applications with maintaining portability and scalability.

How to Run GUI-Based Applications Inside the Docker? A Step-By-Step Guide

The following are the steps to run a GUI based application inside Docker:

Step 1: Install and Start Docker

  • Install the docker software with the following command in the Redhat Operating System:
yum install docker -y
  • Start the Docker service and check the status and restart the service to be it updated with configurations. The Systemctl commands are used to manage system services.
systemctl start docker            // to start the docker service.
systemctl status docker // to check the status .
systemctl restart docker // to restart the service.

Starting the Docker Service

Step 2: Run a Docker Container with Centos Image

  • Now pull an image from DockerHub to base OS Rhel and launch a container and install python3 inside the container. Here we are using the Docker Image as Centos because it comes with graphical drivers in it.
docker run -it — name os_name centos:latest         

Run a Centos Docker Container

  • To run docker container, (-it means interactive terminal, “os_name” you can give according to you easy to remember and “centos: latest” will give you container of centos with the latest version of centos.
  • To install python3 inside the docker container you can choose any version of python, “yum” is used for installing, deleting, and querying software packages.
yum install python3                             

Step 3: Install the GUI Softwares

  • Install the of GUI Application softwares inside container here we are going to install firefox, jupyter & gedit.
yum install firefox -y             // to install firefox 
pip3 install jupyter // to install jupyter
yum install gedit -y // to install gedit
  • The following screenshot shows the installation of Firefox software.

Install the Firefox GUI Softwares

  • The following screenshot shows the installation of gedit GUI software:

Gedit GUI Softwares

  • The following screenshot shows the installation of jupyter GUI Software:

Jupyter Software Installation

Step 4: Create Custom Image from Docker Container

  • Now create an image from the previously launched container and then launch a container of this newly created image(Inside baseOS).
  • Enter ctrl+p+q to come out of the container and make it running or run exit command to stop and come out of it.
  • Create an custom image from the docker container that we used till now with the following command:
docker commit  <container_name>   <image_name>:<version_tag>      

Example:

docker commit os1 img1:v1

creating custom docker image

  • To create an image from your running container,”os_name” is your own os you are going to create so give it a name according to you, “image_name” is the image of your own OS
  • Here, we are going to create so here also give according to you and “version” suppose it’s your first image so give version as v1 or whatever we want to give. The “commit” command is used to create an image from your running container.
docker run -it --name container_name --env=”Display” -- net=host image_name:version    

Running a New GUI Container

  • To run a new docker container from your created os image in which you already install some GUI applications and env displays the environment that it received from its parent(base os), and set image name and version as you mentioned in the previous command. This is your new docker container so give a new name to this os.

 Step 5: Run the GUI Softwares In Container

  • Now here you can check by using the given commands:
firefox                            // to run firefox inside the docker
jupyter notebook // to run jupyter inside the docker
gedit // to run gedit inside the docker
exit                              // to exit from the container
  • The following screenshot shows successful launch and access of firefox GUI from the Container:

Successful Launch of GUI Firefox from Container

  • The following screenshot illustrates the success launch of jupyter notebook GUI:

  • The following screenshot is running GUI Jupyter Notebook

Running GUI Jupyter Notebook

  • Finally we have success run the GUI Based Applications inside the Docker Containers in detailing step by step.

Docker vs Linux Containers: What are Differences?

The following is the differences between Docker Containers and Linux Containers:

Aspect

Docker Containers

Linux Containers (LXC/LXD)

Management Platform

Docker is container management platform that is used for building, deploying and managing the applications using containers.

Linux Containers provides the lower-level containerization technology that is native to the Linux Kernel

Tooling

It provides the a wide set of tools and APIs for container management and deployment.

It offers more flexibility but requires manual configuration using system tools and libraries

Abstraction Level

Docker Containers add a extra layer of abstraction over the Linux container technologies with simplifying container managment and deployment.

It provides a lower-level approach to containerization and offers more control and flexibility but requires manual configuration.

Portability

These are high portable and can run the containers consistently across different environments.

These are also portable but requires more manual configuration to ensure the comptability cross different environments.

Advantages of Docker Containers

The following are the advantages of Docker Containers:

  • Portability: Docker will encapsulates its containers’ applications and their dependencies making them high portable across different environments.
  • Consistency: It ensure the consistent runtime environments for applications regardless of underlying infrastructure.
  • Efficiency: These comes as light weight containers and use shared operating system resources facilitating efficient resource utilization, faster startup times and scalability.
  • Isolation: It provides the isolated environments for applications ensuring each applciation running independently without any interference from the other containers facilitating with security and stability.

The following are the articles people also refered for :-

Article Name

Article Link

Installation of Docker on Ubuntu

Read

Installation of Docker on Windows

Read

Installation of Docker on MacOS

Read



Next Article

Similar Reads