2017-09-29 59 views
2

我創建了一個簡單的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上,我有一個有效的.XauthorityDISPLAY。但是,我沒有做任何特別的設置,所以爲什麼他們不被設置在A的容器上?

最後主機A是Linux Mint 18.1筆記本電腦。主機B是Debian Jessie。

+0

你有沒有在主機A上的GUI,或者你正在運行的所有的它在命令行模式? –

+0

我在主機A和主機B上都有GUI。 – user1381

+0

在主機A上有一個名爲xauth的軟件包嗎?如果不嘗試安裝它。 –

回答

1

啓用的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 
相關問題