While trying to follow these SO instructions for getting a simple Xeyes application running from within a Docker container on a Mac (10.15.5) using XQuartz, this is what I get:
$ docker run -it -e DISPLAY="${IP}:0" -v /tmp/.X11-unix:/tmp/.X11-unix so_xeyes
/work # xeyes
Error: Can’t open display: 192.168.1.9:0
Here are the steps to reproduce:
$ brew install --cask xquartz
Dockerfile:
# Base Image
FROM alpine:latest
RUN apk update &&
apk add --no-cache xeyes
# Set a working directory
WORKDIR /work
# Start a shell by default
CMD ["ash"]
Build image with:
$ docker build -t so_xeyes .
And run the Docker Container/xeyes with this:
# Set your Mac IP address
IP=$(/usr/sbin/ipconfig getifaddr en0)
echo $IP
192.168.1.9
# Allow connections from Mac to XQuartz
/opt/X11/bin/xhost + "$IP"
192.168.1.9 being added to access control list
# Run container
docker run -it -e DISPLAY="${IP}:0" -v /tmp/.X11-unix:/tmp/.X11-unix so_xeyes
When inside the container, type:
xeyes
BUT, I get the following error: Error: Can't open display: 192.168.1.9:0
Does anyone have an idea how I can resolve this or to investigate further?
2
Answers
@MarkSetchell gave me a hint with suggesting I needed to modify the XQuartz Preferences > Security...
But, even after selecting "Allow connections from network clients", it still didn't work.
Then I found a Gist that gave me a little more information here because someone commented that after they made the change, they needed to reboot their Mac (again): https://gist.github.com/cschiewek/246a244ba23da8b9f0e7b11a68bf3285
So, after I made the change AND rebooted my Mac, it worked!
Thanks for guiding me to the final answer!
ALSO NOTE: You do NOT need to volume mount the .X11 directory for this to work:
docker run -it -e DISPLAY="${IP}:0" so_xeyes
By default, X11 does not listen over TCP/IP. You can enable that if you want in Settings, but I don’t think it’s necessary here. Docker should be able to route traffic to the unix domain socket setup by launchd for DISPLAY (eg: /private/tmp/com.apple.launchd.jTIfZplv7A/org.xquartz:0).
If that doesn’t work, you should reach out to Docker to add support for that as it’s much preferred to using TCP for X11 traffic.