In order to run Xorg apps on macOS you will need to install xquartz
and configure it:
brew install --cask --no-quarantine xquartz
defaults write org.xquartz.X11 nolisten_tcp -bool false
defaults write org.xquartz.X11 no_auth -bool false
mkdir -p ~/.xinitrc.d
cat << 'EOF' > ~/.xinitrc.d/xhost-config.sh
#!/bin/sh
xhost +localhost
xhost +\$(hostname)
EOF
chmod +x ~/.xinitrc.d/xhost-config.sh
open -a XQuartz
No need to restart anything or log in/out.
You can then run Xorg apps easily:
docker run -e DISPLAY=docker.for.mac.host.internal:0 petedavidson887/xclock:0.0.1
Note that you will still need to explicitly provide the DISPLAY
env variable every time you run a Docker container. As far as I know there is no way to set a default env variable for all containers — at least not on Docker for macOS.
Run the following, then restart XQuartz:
defaults write org.xquartz.X11 enable_render_extension -bool false
If the misbehaving app is a Java app you can try adding the following option to your docker run
command:
-e JAVA_TOOL_OPTIONS='-Dsun.java2d.xrender=false -Dsun.java2d.pmoffscreen=false -Dremote.x11.workaround=false -Dawt.useSystemAAFontSettings=lcd -Dsun.java2d.renderer=sun.java2d.marlin.MarlinRenderingEngine -Djava2d.font.loadFontConf=true'
(source)