如何从Docker容器中查看GUI应用程序

当我尝试运行一个graphics用户界面,例如xclock,我得到的错误:

Error: Can't open display: 

我正在尝试使用Docker来运行一个ROS容器,我需要看看里面运行的GUI应用程序。

我曾经使用过一个Vagrant虚拟机,并能够使用X11来完成这个任务。

到目前为止,我已经尝试将方法#1和#2放入基于这里的信息的docker文件中: http : //wiki.ros.org/docker/Tutorials/GUI

然后我试着在这里复制大部分dockerfile: https ://hub.docker.com/r/mjenz/ros-indigo-gui/~/dockerfile/

这是我目前的docker文件:

 # Set the base image to use to ros:kinetic FROM ros:kinetic # Set the file maintainer (your name - the file's author) MAINTAINER me # Set ENV for x11 display ENV DISPLAY $DISPLAY ENV QT_X11_NO_MITSHM 1 # Install an x11 app like xclock to test this run apt-get update run apt-get install x11-apps --assume-yes # Stuff I copied to make a ros user ARG uid=1000 ARG gid=1000 RUN export uid=${uid} gid=${gid} && \ groupadd -g ${gid} ros && \ useradd -m -u ${uid} -g ros -s /bin/bash ros && \ passwd -d ros && \ usermod -aG sudo ros USER ros WORKDIR /home/ros # Sourcing this before .bashrc runs breaks ROS completions RUN echo "\nsource /opt/ros/kinetic/setup.bash" >> /home/ros/.bashrc # Copy entrypoint script into the image, this currently echos hello world COPY ./docker-entrypoint.sh / ENTRYPOINT ["/docker-entrypoint.sh"] 

我个人的偏好是注入显示variables和共享unix套接字或X窗口类似的东西:

 docker run -it --rm -e DISPLAY \ -v /tmp/.X11-unix:/tmp/.X11-unix \ -v /etc/localtime:/etc/localtime:ro \ my-gui-image 

共享本地时间只是允许时区匹配,我一直在使用这个电子邮件应用程序。

另一种方法是启动VNC服务器,在该服务器上运行应用程序,然后使用VNC客户端连接到容器。 我不太喜欢那个,因为你最终会在容器内运行两个进程,使信号处理和logging一个挑战。 它的优点是应用程序更好的隔离,所以如果黑客入侵,它不能访问您的X显示器。