背景
打开XQuartz,在桌面右上角菜单栏中的XQuartz偏好设置中的安全性中启用 "允许从网络客户端连接",并重启XQuartz生效,后续操作中要保持XQuartz为打开状态,不要退出XQuartz
报错内容:
root@9b90039a4d17:~# ros2 run turtlesim turtlesim_node
Authorization required, but no authorization protocol specified
qt.qpa.xcb: could not connect to display host.docker.internal:0
qt.qpa.plugin: Could not load the Qt platform plugin "xcb" in "" even though it was found.
This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem.Available platform plugins are: eglfs, linuxfb, minimal, minimalegl, offscreen, vnc, xcb.
配置权限
如果 XQuartz 仍然无法接受来自 Docker 容器的连接,尝试在宿主机上运行以下命令:
xhost + 127.0.0.1
这样可以允许来自本地地址(127.0.0.1)的连接。