Table of Contents
On a Linux desktop with a local X11 display, a Docker container can open a window if it gets the display address, the X11 socket, and valid authorization. The example below uses xclock so you can check the connection with a small app before adapting it to your own image.
Check Docker and your display
Run docker info to confirm that your user can reach the Docker daemon. docker --version only checks the client. Run printf '%sn' "$DISPLAY" from a terminal on your desktop. A local display normally looks like :0 or :1. A Wayland session needs a working Xwayland display for this method. Docker Desktop on macOS and Windows uses a different setup.

Build a small test image
Create a directory with a file named Dockerfile and add the following. See the Dockerfile guide for how the build instructions work.
FROM debian:stable-slim
RUN apt-get update && apt-get install -y --no-install-recommends x11-apps && rm -rf /var/lib/apt/lists/*
CMD ["xclock"]Build it with docker build -t local-xclock .

Authorize the container to open a window
Install xauth on the host if needed. Run the commands below as your desktop user in a Linux shell. The temporary file contains the current display’s authorization record. The family field is adjusted so the record matches from inside the container. If xauth nlist "$DISPLAY" prints nothing, find the authorization file used by your desktop session before starting the container.
cookie=$(mktemp)
xauth nlist "$DISPLAY" | sed 's/^..../ffff/' | xauth -f "$cookie" nmerge -
docker run --rm --network none --user "$(id -u):$(id -g)" --env DISPLAY="$DISPLAY" --env XAUTHORITY=/tmp/container.xauth --mount type=bind,src=/tmp/.X11-unix,dst=/tmp/.X11-unix,readonly --mount type=bind,src="$cookie",dst=/tmp/container.xauth,readonly local-xclock
rm -f "$cookie"X11 access lets a trusted container interact with your desktop session. Use a separate display or VM for apps you don’t trust. The older screenshots below show a host-access method and its resulting window. The cookie method above avoids adding a blanket local-client exception.

If the window fails to open
- Can’t open display: Confirm that
DISPLAYis set and the corresponding socket exists under/tmp/.X11-unix. - Authorization required: Confirm the cookie file contains a record for your session and is readable by the user running inside the container.
- Cannot connect to the Docker daemon: Run
docker infoagain and check the daemon and permissions before troubleshooting X11. See the Docker troubleshooting guide for build and startup checks.
Reader Comments 0
Sign in with email or Google to join the discussion.