X11 forwarding with -v on docker run not working

The -v (or --volume) argument is for mapping paths on the host filesystem into the container’s filesystem. Using :0 is not a (normally) valid path, hence the error - Docker is trying to interpret it as a volume mapping mode (e.g. :ro or :rw) when you use DISPLAY.

${DISPLAY} is an environment variable, usually something like localhost:0 or similar, and is not a valid path.

The correct arguments to export the X11 display from a Docker container are to pass the host’s DISPLAY environment variable, and map the X11 socket from the host:

docker run -ti -e DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unix ubuntu
2 Likes