docker 终端打不开rviz2界面,报错qt.qpa.xcb: could not connect to display

在容器启动挂载了X11服务,然后在容器终端运行rviz、rqt等出现打不开界面情况:

复制代码
root@846616f4a570:/# rviz2 
qt.qpa.xcb: could not connect to display 
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

若第一行display后面没有跟数字(就像上面显示),需要自己设置环境变量:

1.在宿主机查看用的端口

复制代码
echo $DISPLAY

若输出为 :1

2.在容器终端设置相应的环境变量

复制代码
export DISPLAY=:1

3.最后在宿主机打开xhost

复制代码
xhost +

4.启动rviz2、rqt_graph等

相关推荐
Patrick_Wilson3 天前
从「改个端口」到 502:Next.js on k8s 的容器端口、Service 映射与 env 覆盖
docker·kubernetes·next.js
Suroy4 天前
DockerView-Go:用 Go 写一个终端 Docker 监控工具,顺便做了个 Web 仪表盘
docker
云恒要逆袭4 天前
运行你的第一个Docker容器
后端·docker·容器
宋均浩5 天前
# Docker 镜像瘦身实战:从 1.2G 到 80MB 的五个优化步骤
ci/cd·docker
程序员老赵5 天前
10 分钟部署 OpenCode:Docker 一键安装,浏览器打开就能用 AI 写代码(附完整命令与排错)
docker·容器·ai编程
WangMingHua1115 天前
LM Studio Docker 部署——本地大模型一键启动
docker
曲幽7 天前
别再用网页翻译看源码了!你的私人翻译神器LibreTranslate,部署避坑指南来了
python·docker·web·pot·translate·libretranslate·arogstranslate
武子康8 天前
调查研究-183 Apple container:Mac 上用轻量 VM 跑 Linux 容器,Swift 会改写本地容器体验吗?
docker·容器·apple
Alsn8611 天前
等待学习-学习目录:Docker 容器安全攻防
学习·安全·docker
2601_9618752411 天前
决战申论100题2026|最新|范文
linux·容器·centos·debian·ssh·fabric·vagrant