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

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

问题描述

我目前正在尝试在 docker 容器中运行一些 GUI 应用程序.我一直在尝试 jessie frazellegithub.但是,我可以构建图像(或从 docker hub 获取)并运行它们而不会出现任何可见的错误,但是窗口不显示(我看不到应用程序).

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

图像创建自:

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

查了很多资料,发现上面的应该可以了,而且大部分人都说run命令中需要以下几行,

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 that runs the app has to be allowed to communicate with the X server. So I think you have two options:

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

$ xhost +SI:localuser:root

$ xhost +SI:localuser:root

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

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

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

  1. Add a 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

$ useradd -u 1000 my_user

然后使用该用户在容器内运行您的应用.这不需要对接受的主机进行任何更改(因为用户 1000 已经能够连接).

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

看这两个选项,第二个似乎更好,因为它不需要对宿主系统做任何改变,而且如果你需要在主用户无法匹配UID=1000的其他系统中使用这个容器,你可以让容器从 env var 接收正确的 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 set up the correct user (useradd + chown program files).

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

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