移除XQuartz

launchctl unload /Library/LaunchAgents/org.macosforge.xquartz.startx.plist && \
sudo launchctl unload /Library/LaunchDaemons/org.macosforge.xquartz.privileged_startx.plist && \
sudo rm -rf /opt/X11* /Library/Launch*/org.macosforge.xquartz.* /Applications/Utilities/XQuartz.app /etc/*paths.d/*XQuartz  && \
sudo pkgutil --forget org.macosforge.xquartz.pkg  && \
rm -rf ~/.serverauth* && rm -rf ~/.Xauthorit* && rm -rf ~/.cache && rm -rf ~/.rnd && \
rm -rf ~/Library/Caches/org.macosforge.xquartz.X11 && rm -rf ~/Library/Logs/X11

refer: https://gist.github.com/pwnsdx/d127873e24cef159d4d603accaf37ee4

經測試,可移除使用dmg安裝的XQuartz

QGIS Container for Mac OS

首先在終端機中啟動XQuartz,並設定好socat

#取得IP
IP=$(ipconfig getifaddr en0)
#設定X11
open -a XQuartz &
nohup socat TCP-LISTEN:6000,reuseaddr,fork UNIX-CLIENT:\"$DISPLAY\" >/dev/null 2>&1 &

接著在終端機內執行下列指令,就可以啟一個QGIS.

#執行qgis container
docker run -it --rm \
  -e DISPLAY=$IP:0 \
  --volume="$HOME/.Xauthority:/root/.Xauthority:rw" \
  -v /tmp/.X11-unix:/tmp/.X11-unix \
  -v $PWD:/data \
  -w /data \
  slanla/qgis:latest

注意,此指令會將目前所在資料夾($PWD),掛載到container內的/data

X11 GUI application on OSX with docker

首先需要安裝socat以及xquartz

brew install socat
brew cask install xquartz

並建議重開機!

另外最好開啟opengl for x11的功能(refer)

defaults write org.macosforge.xquartz.X11 enable_iglx -bool true

接著開啟XQuartz

open -a XQuartz &

然後就可以不理會XQUartz的視窗

然後在Terminal下達執行X11代理程式

socat TCP-LISTEN:6000,reuseaddr,fork UNIX-CLIENT:\"$DISPLAY\" &

最後就可以在Terminal中啟動docker

docker run -ti --rm \
    -e DISPLAY=192.168.1.1:0 \
    --volume="$HOME/.Xauthority:/root/.Xauthority:rw" \
    -v /tmp/.X11-unix:/tmp/.X11-unix \
    firefox firefox

其中192.168.1.1為MacOS的IP

繼續閱讀