尝试从Docker CentOS容器启动GUI应用程序时出现dbus错误

时间:2019-01-10 04:14:35

标签: docker centos7 x11

我正在尝试从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的最简单示例,但是我失败了。

1 个答案:

答案 0 :(得分:0)

问题出在您的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