Using GUI Application on Docker Container

Saurabh Suthar
3 min readMay 30, 2021
Photo by Ian Taylor on Unsplash

In this blog, we will use a GUI application(like firefox) in Docker using the DISPLAY and /tmp/.X11-unix file redirecting the GUI operations to the base OS use the GUI applications using the concept.

Before moving to the procedure, let’s get familiar with the display in Linux.

Image from Stackoverflow

According to http://www.linfo.org/x_server.html, An X server is a program in the X Window System that runs on local machines (i.e., the computers used directly by users) and handles all access to the graphics cards, display screens and input devices (typically a keyboard and mouse) on those computers.

X11 is the protocol over which the communication takes place between the application and the X server.

Xauth generates or authenticates the cookies or tokens from the machines to the X server and lets them direct display.

/tmp/X11-unix keeps the domain socket with the entry like X0, X1 or X with any number.

Let’s move on to the procedure of running the GUI application on Docker Container.

Firstly, we’ll copy the connection token/cookies by listing them using xauth list which keeps the list of tokens for X server authentication.

Then, we check for displays using the command w or echo $DISPLAY.

Now, we can create the container with following options:

  • i — interactive, t - terminal and together it gives the interactive terminal.
  • — net — connects the container to a network.
  • -v — specify the shared files/folder/volume.
  • -e — shared environmental variable.
docker run -it -e DISPLAY --net=host -v /tmp/.X11-unix centos:latest

After getting the container terminal, install the firefox using yum install firefox -y.

Then, install the xauth to add the token for the authentication.

Add the token, we previously copied here using xauth add paste_token_here.

Start the firefox and it is launched successfully.

Firefox is successfully launched. Yeah!! we did it.

Thanks for reading. Give a clap, if you loved reading it.

Resource: https://unix.stackexchange.com/questions/503806/what-are-x-server-display-and-screen

--

--