因此,我有一个基于C++的Qt5图形用户界面,我想从一个Docker容器中运行它。
当我试着用
docker run --rm -it my_image
这将导致错误输出。
qt.qpa.xcb: could not connect to display localhost:10.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.
所以我开始寻找如何做这个。我找到了GUI Qt Application in a docker container,并以此命名为
QT_GRAPHICSSYSTEM="native" docker run -it -e DISPLAY=$DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unix my_image
导致了同样的错误。
然后我找到了Can you run GUI applications in a Docker container?。
在那里接受的答案似乎是特定于某些应用程序,如Firefox?
向下滚动,我得到了一个解决方案,它告诉我在sshd_config
中设置sshd_config
,然后调用它
docker run -v $HOME:/hosthome:ro -e XAUTHORITY=/hosthome/.Xauthority -e DISPLAY=$(echo $DISPLAY | sed "s/^.*:/$(hostname -i):/") my_image
这会产生上述错误的细微变化:
qt.qpa.xcb: could not connect to display 127.0.1.1:13.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.
在另一个答案之后,我将ENV DISPLAY :0
添加到我的Dockerfile中,并使用
xhost +
XSOCK=/tmp/.X11-unix/X0
docker run -v $XSOCK:$XSOCK my_image
这一次,我错误的第一行是qt.qpa.xcb: could not connect to display :0
。
“然后我又尝试了另一个答案,”
RUN export uid=0 gid=0 && \
mkdir -p /home/developer && \
echo "developer:x:${uid}:${gid}:Developer,,,:/home/developer:/bin/bash" >> /etc/passwd && \
echo "developer:x:${uid}:" >> /etc/group && \
mkdir /etc/sudoers.d/ && \
echo "developer ALL=(ALL) NOPASSWD: ALL" > /etc/sudoers.d/developer && \
chmod 0440 /etc/sudoers.d/developer && \
chown ${uid}:${gid} -R /home/developer
到我的Dockerfile中,并调用docker run -ti --rm -e DISPLAY=$DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unix my_image
,同样的错误。
我还尝试了在http://wiki.ros.org/docker/Tutorials/GUI中描述的几种方法,同样的错误。
我做错了什么吗?请注意,我正在通过SSH在远程机器上工作,当然是打开了X11转发(而且应用程序在Docker之外运行得很好)。还请注意,我编写的是一个客户机-服务器应用程序,服务器部分不需要GUI元素,但共享大部分源代码,它的容器运行良好。
我希望有一个不需要我改变系统的解决方案,因为我首先使用Docker的原因是为了让我的应用程序的用户能够在没有太多麻烦的情况下运行它。
发布于 2021-11-02 23:11:53
您有多个相互覆盖的错误。首先,确保安装了正确的库。如果您的码头形象是基于debian的,它通常看起来像一行。
RUN apt-get update && \
apt-get install -y libqt5gui5 && \
rm -rf /var/lib/apt/lists/*
ENV QT_DEBUG_PLUGINS=1
注意环境变量QT_DEBUG_PLUGINS
。这将使输出更加有用,并引用任何缺少的库。在现在非常详细的输出中,查找如下内容:
Cannot load library /usr/local/lib/python3.9/site-packages/PySide2/Qt/plugins/platforms/libqxcb.so: (libxcb-icccm.so.4: cannot open shared object file: No such file or directory)
粗体部分将是缺少的库文件;您可以在发行版的包管理器(例如,debian上的dpkg -S libxcb-iccm.so.4
)中找到它所在的包。
接下来,像这样开始对接(可以是一行,为了清晰起见,可以分开):
docker run \
-e "DISPLAY=$DISPLAY" \
-v "$HOME/.Xauthority:/root/.Xauthority:ro" \
--network host \
YOUR_APP_HERE
确保用来宾用户的主目录替换/root
。
高级图形(例如游戏、3D建模等)可能还需要安装/dev
和-v /dev:/dev
。请注意,这将使来宾根访问您的硬盘,因此您可能希望以更细粒度的方式复制/重新创建这些设备。
https://stackoverflow.com/questions/65642916
复制相似问题