在Docker容器内:“错误:无法打开显示:localhost:11.0”

时间:2016-07-07 15:34:24

标签: docker x11 xserver

我试图在ssh。

的docker容器中使用带有图形界面的程序

目前,我在一台外部机器上通过ssh连接,其中docker和容器正在运行。在主机上我可以启动像firefox这样正确显示的程序。建立连接:

ssh -Y root@host

当我在docker容器中尝试使用firefox图像时(见下文):

docker run -it --privileged --rm \
    -e DISPLAY=$DISPLAY \
    -v /tmp/.X11-unix:/tmp/.X11-unix \
    -v /root/.Xauthority:/root/.Xauthority:rw \
    firefox

我得到:

Error: cannot open display: localhost:11.0

我已经尝试在主机上设置xhost +,但它仍然无效。 主机运行Scientific Linux release 7.2,并使用。创建docker镜像 来自 http://fabiorehm.com/blog/2014/09/11/running-gui-apps-with-docker/的Dockerfile:

FROM ubuntu:14.04

RUN apt-get update && apt-get install -y firefox

# Replace 1000 with your user / group id
RUN export uid=1000 gid=1000 && \
    mkdir -p /home/developer && \
    echo "developer:x:${uid}:${gid}:Developer,,,:/home/developer:/bin/bash" >> /etc/passwd && \
    echo "developer:x:${uid}:" >> /etc/group && \
    echo "developer ALL=(ALL) NOPASSWD: ALL" > /etc/sudoers.d/developer && \
    chmod 0440 /etc/sudoers.d/developer && \
    chown ${uid}:${gid} -R /home/developer

USER developer
ENV HOME /home/developer
CMD /usr/bin/firefox

1 个答案:

答案 0 :(得分:7)

unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, ExtCtrls; type TForm1 = class(TForm) Panel1: TPanel; procedure FormCreate(Sender: TObject); end; var Form1: TForm1; implementation {$R *.dfm} procedure MD(Instance, Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); begin form1.caption:= inttostr(x)+ ' '+ inttostr(y); end; procedure TForm1.FormCreate(Sender: TObject); function MakeMethod(data, code: pointer): TMethod; begin result.Data:= data; result.Code:= code; end; begin panel1.OnMouseDown:= TMouseEvent(MakeMethod(nil, @MD)); end; end. 添加到--net=host解决了这个问题。