Skip to content

Latest commit

 

History

History
97 lines (70 loc) · 2.29 KB

docker_mac_gui_app.md

File metadata and controls

97 lines (70 loc) · 2.29 KB

Docker for Mac and GUI applications

https://fredrikaverpil.github.io/2016/07/31/docker-for-mac-and-gui-applications/

1. install xquartz

brew install xquartz

reboot Mac

2. setup xquartz

  1. run XQuartz
    open -a XQuartz
    • a xterm window should popup
  2. In the XQuartz preferences, go to the “Security” tab and make sure you’ve got “Allow connections from network clients”
  3. run xhost and allow connections from your local machine
    ip=$(ifconfig en0 | grep inet | awk '$1=="inet" {print $2}')
    xhost + $ip 
  4. find your displaynumber
    display_number=`ps -ef | grep "Xquartz :\d" | grep -v xinit | awk '{ print $9; }'`
    echo $display_number
  5. or you may want to integrate it in your .profile
    # x11
    _ip=`ifconfig en0 | grep inet | awk '$1=="inet" {print $2}'`
    xhost + $_ip > /dev/null 
    export DISPLAY=$_ip:0
  6. test an GUI app, e.g. firefox
    # -v /tmp/.X11-unix:/tmp/.X11-unix 
    docker run --rm  --name firefox -e DISPLAY=$DISPLAY jess/firefox 

better way

xhost + localhost
  • MacOS/Windows Docker Desktop only!
    • use host.docker.internal to access localhost on host from docker container.
docker run --rm  --name firefox -e DISPLAY=host.docker.internal jess/firefox 

Other example

matplotlib X11 test program

import matplotlib
matplotlib.use('tkagg')
import matplotlib.pyplot as plt
plt.plot([1, 2, 3])
plt.show()