前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Docker: GUI 应用,macOS 上如何运行呢?

Docker: GUI 应用,macOS 上如何运行呢?

作者头像
GoCoding
发布2021-05-06 14:27:43
7550
发布2021-05-06 14:27:43
举报
文章被收录于专栏:GoCoding
  • 操作系统: macOS Catalina
  • 基础镜像: continuumio/anaconda3

GoCoding!GoCoding!GoCoding!GoCoding!GoCoding!

Step 1) 安装 XQuartz,允许网络连接

GoCoding!GoCoding!GoCoding!GoCoding!GoCoding!

代码语言:javascript
复制
# 安装
brew cask install xquartz
# 运行
open -a xquartz
  1. 进入 "Preferences > Security"
  2. 勾选 "Allow connections from network clients"

GoCoding!GoCoding!GoCoding!GoCoding!GoCoding!

Step 2) 安装 Docker,准备相关镜像

GoCoding!GoCoding!GoCoding!GoCoding!GoCoding!

代码语言:javascript
复制
brew cask install docker
# 或,直接下载再安装:
#   https://download.docker.com/mac/stable/Docker.dmg

拉取 OpenCV 镜像,用其显示:

代码语言:javascript
复制
docker pull joinaero/anaconda3-opencv3:1.0.0

GoCoding!GoCoding!GoCoding!GoCoding!GoCoding!

Step 3) xhost 添加主机 IP

GoCoding!GoCoding!GoCoding!GoCoding!GoCoding!

代码语言:javascript
复制
# 获取 IP
IP=$(ifconfig en0 | grep inet | awk '$1=="inet" {print $2}')
echo $IP

# 增加 IP
xhost + $IP

GoCoding!GoCoding!GoCoding!GoCoding!GoCoding!

Step 4) OpenCV 预览图片

GoCoding!GoCoding!GoCoding!GoCoding!GoCoding!

XQuartz, xterm 继续执行:

代码语言:javascript
复制
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

预览效果如下:

GoCoding!GoCoding!GoCoding!GoCoding!GoCoding!

结语

GoCoding!GoCoding!GoCoding!GoCoding!GoCoding!

Go coding!

本文参与 腾讯云自媒体同步曝光计划,分享自微信公众号。
原始发表:2020-05-23,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 GoCoding 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
相关产品与服务
容器服务
腾讯云容器服务(Tencent Kubernetes Engine, TKE)基于原生 kubernetes 提供以容器为核心的、高度可扩展的高性能容器管理服务,覆盖 Serverless、边缘计算、分布式云等多种业务部署场景,业内首创单个集群兼容多种计算节点的容器资源管理模式。同时产品作为云原生 Finops 领先布道者,主导开源项目Crane,全面助力客户实现资源优化、成本控制。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档