- Install XQuartz: https://www.xquartz.org/
- Launch XQuartz. Under the XQuartz menu, select Preferences
- Go to the security tab and ensure "Allow connections from network clients" is checked.
- Run
xhost + ${hostname}
to allow connections to the macOS host * - Setup a HOSTNAME env var
export HOSTNAME=`hostname`
* - Add the following to your docker-compose:
environment:
- DISPLAY=${HOSTNAME}:0
volumes:
- /tmp/.X11-unix:/tmp/.X11-unix
* It should be noted that steps 4 and 5 can be automated to run everytime XQuartz starts, but that's outside of the scope of this gist
For anyone arriving... this link contains the only correctly current version. Steps to follow...
It also helped me understand why the volume mount doesn't do anything and what's really going on.
In short: (with optional explanation)
security
tab, make sureAllow connections from network clients
is enabled. Restart XQuartz.xhost +localhost
.-e DISPLAY=host.docker.internal:0
to any docker image you want to forward X to the host.Much thanks to @paul-krohn for putting together his README which clarified a lot.