X11在Docker容器中转发GUI应用 [英] X11 forwarding of GUI app in Docker container

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

问题描述

我目前正在尝试在Docker容器中运行一些GUI应用程序.我一直在

I am currently trying to run some GUI apps in docker containers. I have been trying the ones by jessie frazelle at github. However I can build the images (or get from docker hub) and run them without any visible errors but, the windows don't display (i cant see the app).

我正在Ubuntu 16.04上运行Docker版本1.13.1

I am running Docker version 1.13.1 on Ubuntu 16.04

图像是通过以下方式创建的:

The image is created from:

FROM debian:stretch
MAINTAINER Jessie Frazelle <jess@linux.com>

RUN apt-get update && apt-get install -y \
    libreoffice \
    --no-install-recommends \
    && rm -rf /var/lib/apt/lists/*

ENTRYPOINT [ "libreoffice" ]

我正在使用的运行命令如下:

the run command i am using is below:

docker run -d \
    -v /tmp/.X11-unix:/tmp/.X11-unix \
    -v /etc/localtime:/etc/localtime \
    -e DISPLAY=unix$DISPLAY 
    -v $HOME/Documents:/root/Documents \
    -e GDK_SCALE \
    -e GDK_DPI_SCALE \
    --name libreoffice \
    jess/libreoffice

在搜索了许多资源之后,我发现上面的命令应该起作用,并且大多数人说运行命令中需要以下几行,

After searching many sources, I can see that the above should work, andmost people are saying that the following lines are required in the run command,

    -v /tmp/.X11-unix:/tmp/.X11-unix
    -e DISPLAY=unix$DISPLAY

但是我仍然无法显示窗口.

but still I cant get the window to display.

  1. 我如何才能使用它?
  2. 我从根本上想念什么?

任何帮助将不胜感激.

推荐答案

要能够与X服务器通信,必须允许您运行应用程序的用户与X服务器通信.所以我认为您有两种选择:

To be able to communicate with the X server, the user you run the app has to be allowed to communicate with the X server. So I think you have two options:

1)允许您在容器中拥有的用户连接到X服务器.如果您的应用是使用容器内的用户root运行的,则可以使用:

1) Allow the user you have in the container to connect to the X server. If your app is run with user root inside the container, you can use:

$ xhost +SI:localuser:root

(我不知道这对安全性有何影响,但root应该能够以任何一种方式进行连接...)

(I don't know the security implications of this, but root should be able to connect either way...)

2)在与您的用户会话匹配的容器中添加一个用户.如果您在主机系统中使用的用户的UID = 1000,则可以在容器内创建一个虚拟用户:

2) Add an user in the container that matches your user session. If the user you are using in the host system has UID = 1000, you can create a dummy user inside the container:

$ useradd -u 1000 my_user

然后使用该用户在容器中运行您的应用.不需要更改受支持的主机(因为用户1000已经可以连接).

And then use that user to run your app inside the container. This don't requires any change in the accpeted hosts (as user 1000 is already capable of connection).

查看这两个选项,第二个似乎更好,因为它不需要对主机系统进行任何更改,并且如果需要在主要用户无法匹配UID = 1000的其他系统中使用此容器,则可以使容器从环境变量中接收正确的uid,然后设置正确的用户(useradd + chown程序文件).

Looking at the two options, the second seems better, because it does not require any change in the host system, and if you need to use this container in other systems that the main user could not match UID=1000, you can make the container receive the correct uid from an env var, and then setup the correct user (useradd + chown program files).

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

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