如何从docker容器

时间:2016-11-09 02:20:55

标签: docker x11 ros

当我尝试运行GUI时,例如xclock,我得到错误:

Error: Can't open display: 

我正在尝试使用Docker来运行ROS容器,我需要查看在其中运行的GUI应用程序。

我曾经使用过Vagrant VM做过这个,并且能够使用X11来完成它。

到目前为止,我已尝试根据此处的信息将方式#1和#2放入docker文件中: http://wiki.ros.org/docker/Tutorials/GUI

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

这是我当前的泊坞文件:

# 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"]

1 个答案:

答案 0 :(得分:3)

我个人的偏好是注入显示变量并与以下内容共享unix socket或X windows:

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

分享本地时间只允许时区匹配,我已将其用于电子邮件应用。

另一种选择是启动VNC服务器,在该服务器上运行您的应用程序,然后使用VNC客户端连接到容器。我不太喜欢那个,因为你最终在容器内部运行了两个进程,从而进行信号处理并记录挑战。它确实具有以下优势:应用程序更好地隔离,因此如果被黑客入侵,它就无法访问您的X显示器。