Docker GUI on macOS
Docker GUI 应用,macOS 上如何运行呢?
- 操作系统: macOS Catalina
- 基础镜像: continuumio/anaconda3, based on debian
Step 1) 安装 XQuartz,允许网络连接
# 安装
brew cask install xquartz
# 运行
open -a xquartz
- 进入 "Preferences > Security"
- 勾选 "Allow connections from network clients"
Step 2) 安装 Docker,准备相关镜像
brew cask install docker
# 或,直接下载再安装:
# https://download.docker.com/mac/stable/Docker.dmg
拉取 OpenCV 镜像,用其显示:
docker pull joinaero/anaconda3-opencv3:1.0.0
Step 3) xhost 添加主机 IP
XQuartz, xterm 终端执行:
# 获取 IP
IP=$(ifconfig en0 | grep inet | awk '$1=="inet" {print $2}')
echo $IP
# 增加 IP
xhost + $IP
Step 4) OpenCV 预览图片
XQuartz, xterm 继续执行:
docker run -it --rm \
--name myenv \
-e DISPLAY=$IP:0 \
-v /tmp/.X11-unix:/tmp/.X11-unix \
joinaero/anaconda3-opencv3:1.0.0
conda activate myenv
python - <<EOF
import cv2
while True:
im = cv2.imread("/tmp/GoCoding.png")
im = cv2.resize(im, (256, 256))
cv2.imshow("GoCoding", im)
key = cv2.waitKey(10) & 0xFF
if key == 27 or key == ord('q'):
break
EOF
预览效果如下: