Run GUI Application inside Docker Container

Raja Sharma
3 min readJun 1, 2021

What is Docker?

Docker is a tool designed to make it easier to create, deploy, and run applications by using containers. Containers allow a developer to package up an application with all of the parts it needs, such as libraries and other dependencies, and deploy it as one package. By doing so, thanks to the container, the developer can rest assured that the application will run on any other Linux machine regardless of any customized settings that machine might have that could differ from the machine used for writing and testing the code.

Task Description :-

📌 GUI container on the Docker

(*) Launch a container on docker in GUI mode .

(*) Run any GUI software on the container.

……………………..

Pre-requisite:

  1. Docker installed in the base OS (here, I am using Redhat8 as the base OS)

So, lets start this task…

Step 1: Pull the Docker container image from DockerHub

Here, I have pulled the CentOS image.

cmd : ‘docker pull <image_name>:version’

Step 2 : Launch Container

cmd: docker run -it — name guicontainer — net=host — env=”DISPLAY” — volume=”$HOME/.Xauthority:/root/.Xauthority:rw” centos:latest

— volume=”$HOME/.Xauthority:/root/.Xauthority:rw” centos:latest : to share the host’s XServer with the container by creating a volume.

What is X Server?

X is an application that manages one or more graphics displays and one or more input devices (keyboard, mouse, etc.) connected to the computer.

It works as a server and can run on the local computer or on another computer on the network. Services can communicate with the X server to display graphical interfaces and receive input from the use

  • - -env=”DISPLAY” : to share the host display environment to the container.
  • - -net=host : to run container with host network.

Step 3: Launch the GUI application in the container

cmd: yum install firefox python3 -y

Step 4: installing required libraries for task

cmd: pip3 install jupyter

Step 5:Let’s launch jupyter notebook inside container :

cmd: jupyter notebook — allow-root

Thanks for Reading !!

--

--