如何从Docker容器中查看GUI应用 [英] How to view GUI apps from inside a docker container

查看:204
本文介绍了如何从Docker容器中查看GUI应用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试运行GUI时,例如xclock,出现错误:

When I try to run a GUI, like xclock for example I get the error:

Error: Can't open display: 

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

I'm trying to use Docker to run a ROS container, and I need to see the GUI applications that run inside of it.

我曾经仅使用Vagrant VM做到了这一点,并且能够使用X11来完成它。

I did this once just using a Vagrant VM and was able to use X11 to get it done.

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

So far I've tried putting way #1 and #2 into a docker file based on the info here: http://wiki.ros.org/docker/Tutorials/GUI

然后我尝试在此处复制大多数dockerfile:
https://hub.docker.com/ r / mjenz / ros-indigo-gui /〜/ dockerfile /

Then I tried copying most of the dockerfile here: https://hub.docker.com/r/mjenz/ros-indigo-gui/~/dockerfile/

这是我当前的docker文件:

Here's my current docker file:

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


推荐答案

我的个人偏好是注入显示变量,并与以下对象共享unix套接字或X窗口:

My personal preference is to inject the display variable and share the unix socket or X windows with something like:

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

共享本地时间也只允许时区匹配,我一直在使用

Sharing the localtime just allows the timezone to match up as well, I've been using this for email apps.

另一个选择是启动VNC服务器,在该服务器上运行您的应用程序,然后使用VNC客户端连接到容器。我不太喜欢那个,因为您最终在容器中运行了两个进程,这使得信号处理和记录挑战成为可能。这样做的好处是可以更好地隔离该应用程序,因此,如果该应用程序被黑客入侵,则无权访问您的X显示器。

The other option is to spin up a VNC server, run your app on that server, and then connect to the container with a VNC client. I'm less a fan of that one since you end up with two processes running inside the container making signal handling and logs a challenge. It does have the advantage that the app is better isolated so if hacked, it doesn't have access to your X display.

这篇关于如何从Docker容器中查看GUI应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆