Docker Community Forums

Share and learn in the Docker community.

X11 forwarding with -v on docker run not working

Expected behavior

I expect

xhost + # I know this is not safe this is for the purpose of illustrating my point
docker run -it -v ${DISPLAY}:/tmp/.X11-unix/X0 ubuntu
xhost +
$ docker run -it -v /private/tmp/ ubuntu

to run the container and enables X11.

as the following command is doing on ubuntu

docker run -it -v /tmp/.X11-unix/X0:/tmp/.X11-unix/X0 ubuntu

Actual behavior

I got an error
invalid mode: /tmp/.X11-unix/X0.


I tried to escape the : character in the OS DISPLAY environment variable with a \ or quitting all the expanded variable and I still got the same error.

  • the output of:
    • Moby Menu > Diagnose & Feedback on OS X
      Docker for Mac: version: mac-v1.12.0-beta17
      OS X: version 10.11.5 (build: 15F34)
      logs: /tmp/20160708-111358.tar.gz
      [OK] docker-cli
      [OK] app
      [OK] menubar
      [OK] virtualization
      [OK] system
      [OK] osxfs
      [OK] db
      [OK] slirp
      [OK] moby-console
      [OK] logs
      [OK] vmnetd
      [OK] env
      [OK] moby
      [OK] driver.amd64-linux
  • a reproducible case if this is a bug, Dockerfiles FTW
  • page URL if this is a docs issue or the name of a man page
  • host distribution and version ( OSX 10.10.x, OSX 10.11.x, Windows, etc )

Steps to reproduce the behavior

any ubuntu image.

1 Like

check on latest release to date
Version 1.12.0-rc3-beta18 (build: 9996)
that this is still happening.

I try to do the same. I am getting the same error in Version 1.12.0-rc3-beta18 (build: 9996)

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