GUI application in Docker Container

Govind Bhardwaj
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 ( In my case I will run Jupyter Notebook on Firefox)

To run GUI application inside we will use X11-Forwarding . The package we will use for X11-Forwarding is X11-server .

Basic Introduction About X11 Server -

  • The X Window System (also known as X11, or simply X) is a client/server windowing system for bitmap displays.
  • It is implemented on most UNIX-like operating systems and has been ported to many other systems.
  • The X server is the program or dedicated terminal that displays the windows and handles input devices such as keyboards, mice, and touchscreens. The clients are applications.
  • To know more about X11 server visit the link -
  • To connecting base X11 server to container client we will use “Unix Domain Socket” .
  • A Unix domain socket or IPC socket (inter-process communication socket) is a data communications endpoint for exchanging data between processes executing on the same host operating system.
  • OS have a directory “/tmp/.X11-unix” . This directory have socket file . For connecting X11 server use this file . So I will mount this directory to container “/tmp/.X11-unix”
  • We have to also pass “DISPLAY” environment variable .

Step -1) Create Image With FireFox Package

  • We created a Dockerfile to create a image which will have “python3” and “firefox” library . And “jupyter” python library will also there . Container which are launched with the help of this image their work directory will be “/root/workspace” . Whenever any container will be launched then “jupter notebook” will run .
FROM      centos
RUN mkdir -p /root/workspace &&\
yum install python3 firefox -y &&\
pip3 install jupyter scikit-learn numpy pandas
WORKDIR /root/workspace
CMD jupyter notebook --allow-root
  • Build the Image with name “gui:latest”
# docker build -t gui:latest .

Step -2) Run Docker Container

Run docker container with X11 forwarding

# docker run -it --name guiosTesting -e=DISPLAY=$DISPLAY -v /tmp/.X11-unix/:/tmp/.X11-unix/ gui:latest

Step -3) Check with dummy code -

  • To check “Untitled.ipynb” file is created or not in “/root/workspace”
# docker exec -it guiosTesing bash      (Run this on Docker Host)(Run below both commands on Docker Container)
# ls
# cat Untitled.ipynb

File “Untitled.ipynb” is there . Now our task is successfully completed .

--

--