【问题标题】:dbus errrors when trying to start GUI app from Docker CentOS container尝试从 Docker CentOS 容器启动 GUI 应用程序时出现 dbus 错误
【发布时间】:2019-06-04 22:07:27
【问题描述】:

我正在尝试从 CentOS 容器运行 GUI。我试图关注this example。这是我的 Dockerfile:

#!/bin/bash
FROM centos:7
#RUN yum install -y firefox dbus dbus-x11
RUN yum install -y firefox 
# Replace 0 with your user / group id
RUN export uid=1000 gid=100
RUN mkdir -p /home/developer
RUN echo "developer:x:${uid}:${gid}:Developer,,,:/home/developer:/bin/bash" >> /etc/passwd
RUN echo "developer:x:${uid}:" >> /etc/group
RUN echo "developer ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers
RUN chmod 0440 /etc/sudoers
RUN chown ${uid}:${gid} -R /home/developer
#RUN dbus-uuidgen > /var/lib/dbus/machine-id

#RUN export $(dbus-launch)

USER developer
ENV HOME /home/developer
CMD /usr/bin/firefox

然后我在终端中运行以下命令。

   docker run -ti --rm \
       -e DISPLAY=$DISPLAY \
       -v /tmp/.X11-unix:/tmp/.X11-unix \
       firefox

    process 8: D-Bus library appears to be incorrectly set up; failed to read machine uuid: UUID file '/etc/machine-id' should contain a hex string of length 32, not length 0, with no other text
    See the manual page for dbus-uuidgen to correct this issue.
      D-Bus not built with -rdynamic so unable to print a backtrace
    Running without a11y support!
    No protocol specified
    Error: cannot open display: :0.0

我尝试过this solution,在我的 Dockerfile 中添加以下行,

# apt-get install -y dbus
# dbus-uuidgen > /var/lib/dbus/machine-id

但这并没有解决问题。有什么想法吗?

编辑:我的主机操作系统是 Arch Linux。我真的想在 CentOs 中运行这个例子。我真的不需要一个运行 Firefox GUI 的容器。我只是想获得一个在 CentOS 容器中运行的 GUI 的最简单示例,但我失败了。

【问题讨论】:

  • 你的主机上有什么操作系统?
  • @vvchik 我的主机操作系统是 Arch Linux。谢谢。

标签: docker centos7 x11


【解决方案1】:

问题在于您的 DockerFile,您的基础映像是 Centos,其余的命令是您为 Ubuntu 运行的。

FROM ubuntu

RUN apt-get update && apt-get install -y firefox

# Replace 1000 with your user / group id
RUN export uid=1000 gid=1000 && \
    mkdir -p /home/developer && \
    echo "developer:x:${uid}:${gid}:Developer,,,:/home/developer:/bin/bash" >> /etc/passwd && \
    echo "developer:x:${uid}:" >> /etc/group && \
    echo "developer ALL=(ALL) NOPASSWD: ALL" > /etc/sudoers.d/developer && \
    chmod 0440 /etc/sudoers.d/developer && \
    chown ${uid}:${gid} -R /home/developer

USER developer
ENV HOME /home/developer
CMD /usr/bin/firefox

你的运行命令将是

docker run -ti --rm  -e DISPLAY=$DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unix firefox

上面的图像在 Ubuntu 18.04 中测试并且工作正常。

对于窗口尝试这样

docker run -ti --rm -e DISPLAY=$DISPLAY firefox

您在 docker 注册表上检查上述图像。

docker pull adilm7177/firefox

【讨论】:

  • 您知道如何更改我的 Dockerfile 以适用于 CentOs7 吗?我真的在尝试运行另一个仅在 RedHat 和 CentOs 中受支持的 GUI 程序。
  • 你也可以试试ubuntu,但你没有提到我怀疑你真的对centos感兴趣
  • 我确实需要 CentO,因为它支持我尝试运行的软件 (ANSYS)。但是我确实尝试了您的 Ubuntu 示例,但遇到了此错误:未指定协议错误:无法打开显示::0 所以我不知道。我会继续寻找答案。作为参考,我的主机操作系统是 Arch Linux,我的 Docker 版本是 1:18.09.1-1。
猜你喜欢
  • 2020-10-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多