Skip to content

Instantly share code, notes, and snippets.

@cschiewek
Last active November 21, 2024 20:26
Show Gist options
  • Save cschiewek/246a244ba23da8b9f0e7b11a68bf3285 to your computer and use it in GitHub Desktop.
Save cschiewek/246a244ba23da8b9f0e7b11a68bf3285 to your computer and use it in GitHub Desktop.
X11 in docker on macOS

To forward X11 from inside a docker container to a host running macOS

  1. Install XQuartz: https://www.xquartz.org/
  2. Launch XQuartz. Under the XQuartz menu, select Preferences
  3. Go to the security tab and ensure "Allow connections from network clients" is checked.
  4. Run xhost + ${hostname} to allow connections to the macOS host *
  5. Setup a HOSTNAME env var export HOSTNAME=`hostname`*
  6. 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

@idossha
Copy link

idossha commented Oct 21, 2024

I was stuck on this for a while. Eventually I realized there might be a problem with Xquartz. Indeed after downgrading as suggested by @R1kk3r and following these steps below everything worked fine.

defaults write org.macosforge.xquartz.X11 nolisten_tcp -bool false
export DISPLAY=localhost:0
xhost +localhost
xhost +$(hostname)

Hope that helps.

@devnoname120
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment