Skip to content
vast-cow's blog
Go back

Running X11 apps inside a rootless Docker container (by passing xauth cookies)

Edit page

Rootless Docker is great for reducing host privileges, but GUI apps can be a bit tricky—especially when you want an X11 app inside a container to show up on your host display.

This post walks through a simple, reliable approach:


Prerequisites


What we’re doing (high-level)

X11 access typically requires:

  1. The correct DISPLAY target (e.g., 10.0.2.2:10)
  2. A valid authentication cookie (MIT-MAGIC-COOKIE-1)

Your host stores these cookies in an Xauthority database. We’ll copy the relevant cookie value from the host and inject it into the container’s Xauthority using xauth add.


On the host, run:

$ xauth list "$DISPLAY"
hostname/unix:10  MIT-MAGIC-COOKIE-1  0a1b2c...

Copy the cookie part (0a1b2c...). You’ll use it inside the container.

Note: the :10 portion is the display number. Yours might be :0, :1, etc.


2) Start the container (rootless Docker)

Example (using an image called wine, but any image is fine):

$ docker run -it --rm --name wine-x11 \
  --network host \
  -e DISPLAY=host.docker.internal:12.0 \
  -v ./root:/root \
  -v ./work:/work \
  wine bash

Why these flags?

If host.docker.internal doesn’t resolve in your environment, don’t worry—you can use an explicit host IP (as shown next).


Inside the container shell, register the cookie:

# xauth add 10.0.2.2:10 MIT-MAGIC-COOKIE-1 "${cookie}"

Replace ${cookie} with the cookie string you copied from the host (0a1b2c...).

About this warning

You may see:

xauth:  file /root/.Xauthority does not exist

This is just a warning meaning the file doesn’t exist yet. xauth add will create it, so it’s safe to ignore.


4) Test with xev

Now verify X11 forwarding from container to host:

# DISPLAY=10.0.2.2:10 xev

If a small window opens and prints keyboard/mouse events, it’s working.


Troubleshooting checklist


Summary

To run an X11 app inside a rootless Docker container:

  1. Read the host cookie: xauth list "$DISPLAY"
  2. Start the container (--network host is simplest)
  3. Add the cookie in the container: xauth add ... MIT-MAGIC-COOKIE-1 ...
  4. Launch an X11 client: DISPLAY=... xev

This pattern is minimal, explicit, and works well for debugging and quick setups.


Edit page
Share this post:

Comments


Previous Post
Audio Segmentation with YAMNet: Detecting Speech, Music, and Silence
Next Post
Which NVIDIA HPC SDK Versions Bundle (or Don’t Bundle) CUDA 12 and CUDA 13