Xquartz:可以打开显示Mac OS
在尝试关注这些指令使用Xquartz在Mac(10.15.5)上从Docker容器中运行的简单Xeyes应用程序,这就是我得到的:
$ DOCKER RUN -IT -IT -E DISPLAS =“ $ {ip}:0” -V / tmp/.x11-unix:/tmp/.x11-unix so_xeyes
/work#xeyes 错误:无法打开显示:192.168.1.9:0
这是复制的步骤:
$ brew install -cask xquartz
dockerfile:
# Base Image
FROM alpine:latest
RUN apk update && \
apk add --no-cache xeyes
# Set a working directory
WORKDIR /work
# Start a shell by default
CMD ["ash"]
构建图像
用: $ docker build -docker build -t so_xeyes 。
并使用以下方式运行Docker Container/Xeyes:
# Set your Mac IP address
IP=$(/usr/sbin/ipconfig getifaddr en0)
echo $IP
192.168.1.9
# Allow connections from Mac to XQuartz
/opt/X11/bin/xhost + "$IP"
192.168.1.9 being added to access control list
# Run container
docker run -it -e DISPLAY="${IP}:0" -v /tmp/.X11-unix:/tmp/.X11-unix so_xeyes
在容器内,键入:
Xeyes
但是,我会收到以下错误:错误:无法打开显示:192.168.1.9:0
有人知道我如何解决此问题或进一步研究?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
@MarkSetchell给了我一个暗示,建议我需要修改Xquartz 首选项> Security ...
但是,即使选择“允许网络客户端的连接”,它仍然无法正常工作。
然后我找到了一个要点,在这里给了我更多信息,因为有人评论说,他们进行了更改后,他们需要重新启动Mac(再次):https://gist.github.com/cschiewek/246a244ba23da8b9f0e7b11a68bf3285
So, after I made the change AND rebooted my Mac, it worked!
感谢您指导我获得最终答案!
另请注意:您不需要汇编.x11目录才能工作:
docker run -e it -e display =“ $ {ip}:0” so_xeyes
@MarkSetchell gave me a hint with suggesting I needed to modify the XQuartz Preferences > Security...
But, even after selecting "Allow connections from network clients", it still didn't work.
Then I found a Gist that gave me a little more information here because someone commented that after they made the change, they needed to reboot their Mac (again): https://gist.github.com/cschiewek/246a244ba23da8b9f0e7b11a68bf3285
So, after I made the change AND rebooted my Mac, it worked!
Thanks for guiding me to the final answer!
ALSO NOTE: You do NOT need to volume mount the .X11 directory for this to work:
docker run -it -e DISPLAY="${IP}:0" so_xeyes
默认情况下,X11不会通过TCP/IP聆听。您可以在设置中启用,但我认为这里不需要。 Docker应该能够将流量路由到Unix域插座设置bunaindd for Display(例如:/private/tmp/com.apple.launchd.jtifzplv7a/org.xquartz:0)。
如果这样做不起作用,您应该与Docker联系以增加对此的支持,因为它更喜欢将TCP用于X11流量。
By default, X11 does not listen over TCP/IP. You can enable that if you want in Settings, but I don't think it's necessary here. Docker should be able to route traffic to the unix domain socket setup by launchd for DISPLAY (eg: /private/tmp/com.apple.launchd.jTIfZplv7A/org.xquartz:0).
If that doesn't work, you should reach out to Docker to add support for that as it's much preferred to using TCP for X11 traffic.