Run GUI application in Docker Container

kundan singh
3 min readJun 1, 2021

Task Description 📄

📌 GUI container on the Docker

🔅 Launch a container on docker in GUI mode

🔅 Run any GUI software on the container

We will proceed step by step

Step-1

First we have to pull image using command# docker pull image_name
after that we have to launch container , but normally container are provides us command-line interface(CLI) .sometimes we need to work with the application which gives GUI. for these condition we can use GUI application also in our docker container.

For using GUI in container we have to Forward An X Socket to A Docker Container

Providing a Docker container with access to your host’s X socket is a straightforward procedure. The X socket can be found in /tmp/.X11-unix on your host. The contents of this directory should be mounted into a Docker volume assigned to the container. You’ll need to use the host networking mode for this to work.

Let’s see practical . I already install docker so i have to just start it .

Step-2

Now the main thing is we have to launch container with GUI support

So You need to share your host X11 socket with the container and export your display variables.

-v stands for Bind mount a Volume

-e stands for Export Environment variables

$docker run -it -e DISPLAY=$DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unix <<yourcontainer>>

Step-3

Now our container is launched . now we install some application and check whether these are working or not.so we install Firefox and will check for it.

yum install firefox

Step-4

Now if we run Firefox ,then it will open in container (GUI form)

Let’s run another application, so we will try to run Jupyter Notebook .
to run these application first we have to install python3 and after that we require to install jupyter notebook

yum install python3

pip3 install jupyter

Jupyter Notebook is installed .now let’s run it
using command

jupyter notebook — allow -root

Similarly we can run other applications on docker container .

--

--