相同的Docker镜像转发X11一个主机但不在另一个主机上
问题描述:
我创建了一个简单的Docker镜像,其中包含SSH + xeyes。我运行该容器,通过使用X11转发的SSH连接到容器,并希望能够显示xeyes。相同的Docker镜像转发X11一个主机但不在另一个主机上
我已经建立并在主机A上运行的泊坞容器当我连接到容器,这是行不通的Error: Can't open display:
我有建立和另一台主机上运行的泊坞容器,B. 和它的作用就像一种魅力。
我不明白的区别...
我Dockerfile:
FROM ubuntu:16.04
ENV SSH_PASSWORD "rootpass"
RUN apt-get update
RUN apt-get install -qqy x11-apps openssh-server ssh
# Install SSH access
RUN mkdir /var/run/sshd
RUN echo "root:$SSH_PASSWORD" | chpasswd
RUN sed -i 's/PermitRootLogin prohibit-password/PermitRootLogin yes/' /etc/ssh/sshd_config
RUN sed '[email protected]\s*required\s*[email protected] optional [email protected]' -i /etc/pam.d/sshd
CMD [ "/usr/sbin/sshd", "-D" ]
EXPOSE 22
在主机A和B,我做的:
- 构建图像与
docker build -t myeyes .
- 运行容器:
docker run -d -p 7222:22 --name myeyes myeyes
。
然后,从另一台主机C,我做xhost +
我尝试这些容器:
它失败为A上的容器:
$ ssh -X -p 7222 [email protected]
...
# env | grep DISPLAY
# xeyes
Error: Can't open display:
# grep X11Forward /etc/ssh/sshd_config
X11Forwarding yes
# ls -al
-rw------- 1 root root 180 Sep 29 09:32 .bash_history
-rw-r--r-- 1 root root 3106 Oct 22 2015 .bashrc
drwx------ 2 root root 4096 Sep 29 09:04 .cache
-rw-r--r-- 1 root root 148 Aug 17 2015 .profile
它为容器的工作对B:
$ ssh -X -p 7222 [email protected]
...
# env | grep DISPLAY
DISPLAY=localhost:10.0
# grep X11Forward /etc/ssh/sshd_config
X11Forwarding yes
# ls -al
-rw------- 1 root root 58 Sep 29 09:34 .Xauthority
-rw------- 1 root root 59 Sep 29 09:33 .bash_history
-rw-r--r-- 1 root root 3106 Oct 22 2015 .bashrc
drwx------ 2 root root 4096 Sep 29 09:21 .cache
-rw-r--r-- 1 root root 148 Aug 17 2015 .profile
# cat .Xauthority
...
MAGIC COOKIE
...
# xeyes
否在B上,我有一个有效的.Xauthority和DISPLAY。但是,我没有做任何特别的设置,所以为什么他们不被设置在A的容器上?
最后主机A是Linux Mint 18.1笔记本电脑。主机B是Debian Jessie。
答
启用的SSH详细信息,我注意到以下消息:
debug2: x11_get_proto: /usr/bin/xauth list :0 2>/dev/null
debug1: Requesting X11 forwarding with authentication spoofing.
...
X11 forwarding request failed on channel 0
然后我在网上搜索了"X11 forwarding request failed on channel 0"和找到了解决办法:在/ etc/SSH/sshd_config中,添加:
X11UseLocalhost no
和然后ssh -X在任何地方都能正常工作。
所以,这个命令必须被添加到Dockerfile我的容器:
RUN echo "X11UseLocalhost no" >> /etc/ssh/sshd_config
你有没有在主机A上的GUI,或者你正在运行的所有的它在命令行模式? –
我在主机A和主机B上都有GUI。 – user1381
在主机A上有一个名为xauth的软件包吗?如果不尝试安装它。 –