当映像在docker机器上运行时,X11转发不起作用,但是如果映像在没有docker机器上运行时,X11转发则可以正常工作 [英] X11 forwarding doesn’t work when image runs in docker machine but it works fine if the image is run w/o a docker machine

查看:173
本文介绍了当映像在docker机器上运行时,X11转发不起作用,但是如果映像在没有docker机器上运行时,X11转发则可以正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个基于debian的docker容器,当我像这样运行它时,它可以工作,

I have a docker container based on debian and it works when I run it like,

"docker run -ti --name devworkstation --rm --net=host -v /var/run/docker.sock:/var/run/docker.sock -e DISPLAY=$env:DISPLAY xxxx/xxxx:devworkstation"

通过工作,我的意思是出现bash命令提示符,并且在我运行xeyes时,可以看到Windows 10计算机上的窗口. (x11转发有效.)

By works, I mean that the bash command prompt comes up and when I run xeyes, I see the window on my windows 10 computer as I expect. (x11 forwarding works.)

($ env:DISPLAY ="myWinIP:0.0")

($env:DISPLAY = "myWinIP:0.0")

然后我创建了一个名为"dockerExternalSwitch"的新外部虚拟交换机,以及一个名为"docker-machine create -d hyperv --hyperv-virtual-switch dockerExternalSwitch dev1"的docker计算机.

I then created a new external virtual switch named, "dockerExternalSwitch," and a docker machine with, "docker-machine create -d hyperv --hyperv-virtual-switch dockerExternalSwitch dev1"

我根据docker-machine env dev1设置了我的环境.然后,我在docker机器上运行与上述相同的docker run命令.如我所料,它会弹出我的命令提示符,但是当我运行xeyes时,出现错误:

I set up my environment according to docker-machine env dev1. I then run the same docker run command as above on the docker machine. It brings up my command prompt as I expect, but when I run xeyes, I get an error:

错误:无法打开显示:xxx.xxx.xxx.xxx:0.0

Error: Can’t open display: xxx.xxx.xxx.xxx:0.0

我还在debian映像上安装了Firefox.它给出了类似的错误: 无法初始化服务器:不支持百老汇显示类型:xxx.xx.xx.xxx:0.0 错误:无法打开显示:xxx.xxx.xxx.xxx:0.0

I also have firefox installed on the debian image. It gives a similar error: Unable to init server: Broadway display type not supported: xxx.xx.xx.xxx:0.0 Error: cannot open display: xxx.xxx.xxx.xxx:0.0

由于它在我直接运行(没有docker机器)时可以工作,而在我使用docker机器时失败,所以我想知道它是否与网络有关.

Since it works when I run it directly (w/o a docker machine) and fails when I use the docker machine, I’m wondering if it is network related.

Dockerfile内容:

Dockerfile contents:

from debian:9.5
RUN apt-get update
RUN DEBIAN_FRONTEND=noninteractive apt-get install -y firefox-esr
RUN DEBIAN_FRONTEND=noninteractive apt-get install -y vim git curl
RUN DEBIAN_FRONTEND=noninteractive apt-get install -y build-essential
RUN DEBIAN_FRONTEND=noninteractive apt-get install -y gdb valgrind
RUN DEBIAN_FRONTEND=noninteractive apt-get install -y qt4-default
RUN DEBIAN_FRONTEND=noninteractive apt-get install -y dos2unix tcpdump netcat
RUN DEBIAN_FRONTEND=noninteractive apt-get install -y apt-utils
RUN DEBIAN_FRONTEND=noninteractive apt-get install -y linux-image-rt-amd64
RUN DEBIAN_FRONTEND=noninteractive apt-get install -y task-mate-desktop
RUN env
CMD /bin/bash

我尝试了所有可以在互联网上找到的x11转发建议.我已经在堆栈溢出中搜索了建议.我尚未找到解决方案,它似乎与docker计算机有关.关于我可以尝试的任何建议将不胜感激.

I’ve tried about all of the x11 forwarding suggestions I could find on the internet. And I've searched stack overflow for suggestions. I haven't found a solution and it appears to be related to the docker machine. Any suggestions on what I could try would be greatly appreciated.

(仅供参考,我使用docker-machine的原因是,我有示例代码连接到充当docker-machine的网络摄像机,但是没有运行docker machine的网络摄像机却没有.)

(FYI, The reason I'm working with the docker-machine is that I have sample code that connects to a network camera that works as a docker-machine but not when I run without the docker machine. )

推荐答案

我知道了.当不使用docker机器运行映像时,DISPLAY变量必须是我的Windows计算机的ip地址.在docker机器上运行映像时,我必须将DISPLAY环境变量更改为我创建的新虚拟交换机的IP地址.在我的脚本文件中,我使用了以下代码:

I figured it out. When running the image w/o the docker machine, the DISPLAY variable had to be the ip address of my windows computer. When running the image with the docker machine, I had to change the DISPLAY environment variable to be the IP address of the new virtual switch I had created. In my script file I used the following code:

#$local is true when running w/o the docker machine
if ($local) {
     $IPv4=get-netipaddress -InterfaceAlias "vEthernet (Default Switch)" -AddressFamily "IPv4" | select -expand IPAddress
 }
 else {
     $IPv4=get-netipaddress -InterfaceAlias "vEthernet (dockerExternalSwitch)" -AddressFamily "IPv4" | select -expand          IPAddress
 }
debug-output "IPv4: $($IPv4)"
 $env:DISPLAY=$IPv4 + ":0.0"

if (! $local) {
  #set up to use docker-machine using docker-machine env dev1
}

docker run -ti --name devworkstation --rm --net=host -v /var/run/docker.sock:/var/run/docker.sock -e DISPLAY=$env:DISPLAY    xxx/xxx:devworkstation

现在,x11转发可与docker-machine一起使用,而无需使用docker-machine.

Now the x11 forwarding works with and w/o the docker-machine.

这篇关于当映像在docker机器上运行时,X11转发不起作用,但是如果映像在没有docker机器上运行时,X11转发则可以正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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