Run GUI Application in Docker Container

less than 1 minute read

With this snippet, you can run a GUI application in your docker container using X server on your host machine.

Test Environment

  • Ubuntu 18.04.4(x86_84)
  • Docker 19.03.8

Code Snippet

xhost +local:root
docker run -it \
--env="DISPLAY" \
--env="QT_X11_NO_MITSHM=1" \
--volume="/tmp/.X11-unix:/tmp/.X11-unix:rw" \
ubuntu

Details

1. Add localhost to the list allowed to access to the X server.

xhost is a server access control program for X. The syntax is xhost [[+-]name ...].

Click here for more information.

xhost +local:root

2. Run docker container with environment variables and volume.

DISPLAY environment variable generally points to an X Display server located on your local computer.

QT_X11_NO_MITSHM=1 environment variable will fix graphical issue with application which depend on libqt4.(frankly, I’m not sure about this)

And the /tmp/.X11-unix directory has a Unix-domain socket for X11 server and client.

docker run -it \
--env="DISPLAY" \
--env="QT_X11_NO_MITSHM=1" \
--volume="/tmp/.X11-unix:/tmp/.X11-unix:rw" \
ubuntu

Tags:

Updated:

Leave a comment