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等

相关推荐
感哥28 分钟前
Docker镜像
docker
Dontla32 分钟前
Dockerfile解析器指令(Parser Directive)指定语法版本,如:# syntax=docker/dockerfile:1
java·docker·eureka
楠神说软件测试3 小时前
Docker命令(全)
docker
LuiChun3 小时前
docker desktop更新到【4.45.0 】后,旧容器镜像都丢失了
docker·容器·dubbo
子兮曰3 小时前
🔥C盘告急!WSL磁盘暴增?三招秒清20GB+空间
前端·windows·docker
ZLRRLZ3 小时前
【Docker】Docker安装
运维·docker·容器
Dxy12393102165 小时前
Docker常用命令详解
docker·容器·eureka
清寒敲代码5 小时前
k8s核心技术-Helm
运维·容器·kubernetes
魏 无羡5 小时前
k8s 获取真实ip地址
tcp/ip·容器·kubernetes
人工智能训练师5 小时前
在Ubuntu中如何使用PM2来运行一个编译好的Vue项目
linux·运维·服务器·vue.js·ubuntu·容器