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:

  1. pass the XAUTHORITY and DISPLAY env. variables
  2. mount the X11 socket directory: /tmp/.X11-unix
  3. mount the file stored in XAUTHORITY variable with the magic cookie

SELinux will also require:

  1. --security-opt label=type:container_runtime_t

And if you don't want to run the app inside the container as root then:

  1. --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}"