HowTo#
Run GUI Application inside a Container#
The following is a working snippet for Xorg with SELinux enabled.
I was testing this with podman but I want to believe that docker works
too.
You need to:
- pass the
XAUTHORITYandDISPLAYenv. variables - mount the X11 socket directory:
/tmp/.X11-unix - mount the file stored in
XAUTHORITYvariable with the magic cookie
SELinux will also require:
--security-opt label=type:container_runtime_t
And if you don't want to run the app inside the container as root then:
--userns keep-id
So the minimal oneliner to run X11 based GUI application inside a container
should be this (set DOCKER as podman or docker and IMAGE with your
image, e.g. ubuntu:24.04):
${DOCKER} run -it \
--userns keep-id \
--env=XAUTHORITY="${XAUTHORITY}" \
--env=DISPLAY="${DISPLAY}" \
-v "/tmp/.X11-unix:/tmp/.X11-unix:ro" \
-v "${XAUTHORITY}:${XAUTHORITY}:ro" \
--security-opt label=type:container_runtime_t \
"${IMAGE}"