Macos 如何将Mac Docker转发到X11?

Macos 如何将Mac Docker转发到X11?,macos,docker,xquartz,Macos,Docker,Xquartz,使用和OS X 10.11.5(15F34),我试图将我的一个容器转发到X11 首先,我从bash shell安装XQuartz: $ brew cask install xquartz ==> Downloading https://dl.bintray.com/xquartz/downloads/XQuartz-2.7.9.dmg ######################################################################## 100.

使用和OS X 10.11.5(15F34),我试图将我的一个容器转发到X11

首先,我从bash shell安装XQuartz:

$ brew cask install xquartz

==> Downloading https://dl.bintray.com/xquartz/downloads/XQuartz-2.7.9.dmg
######################################################################## 100.0%
==> Verifying checksum for Cask xquartz
==> Running installer for xquartz; your password may be necessary.
==> Package installers may write to any location; options such as --appdir are ignored.
Password:
==> installer: Package name is XQuartz 2.7.9
==> installer: Installing at base path /
==> installer: The install was successful.
Turns out there's a bug in XQuartz 2.7.9.

When using XQuartz 2.7.10_beta2, it works.

I have xQuartz 2.7.11 installed on Mac OS.

I was getting the following error

<program>: cannot connect to X server <ip>:0
when trying to run docker container. I tried downgrading XQuartz but it still didn't fix my issue.

A crucial piece to to the setup is to add your ip access control list for xhost.

xhost + $(ipconfig getifaddr en0)

After adding the ip to xhost, everything works. There is no need to downgrade Xquartz version.

Solution

After installing XQuartz you will need to restart your computer as horcle_buzz suggested; starting a new terminal session is not enough.

After a reboot you can grant access for whatever you need using the
xhost
command. Just be careful and understand the consequences of too permissive a rule. This other discussion has more info: Running Chromium inside Docker - Gtk: cannot open display: :0

Additional findings

Some extra things I discovered along the way:

  • XQuartz must be running first:
    $ open -a XQuartz
    
    $brew cask安装xquartz
    ==>下载https://dl.bintray.com/xquartz/downloads/XQuartz-2.7.9.dmg
    ######################################################################## 100.0%
    ==>验证Cask xquartz的校验和
    ==>正在运行xquartz的安装程序;您的密码可能是必需的。
    ==>软件包安装程序可以写入任何位置;忽略诸如--appdir之类的选项。
    密码:
    ==>安装程序:包名为XQuartz 2.7.9
    ==>安装程序:在基本路径安装/
    ==>安装程序:安装成功。
    
    结果发现XQuartz 2.7.9中有一个bug


    使用XQuartz 2.7.10u beta2时,它可以工作

    我在Mac OS上安装了xQuartz 2.7.11

    我得到了以下错误
    
    :无法连接到X服务器:0
    
    尝试运行docker容器时。我尝试降级XQuartz,但仍然无法解决我的问题

    设置的一个关键部分是为xhost添加ip访问控制列表

    xhost+$(ipconfig getifaddr en0)
    

    将ip添加到xhost后,一切正常。没有必要降级Xquartz版本

    解决方案 安装XQuartz后,您将需要重新启动计算机as;启动新的终端会话是不够的

    重新启动后,您可以使用
    xhost
    命令授予对所需内容的访问权限。只是要小心,理解过于宽松的规则的后果。此其他讨论包含更多信息:

    其他调查结果 一路上我发现了一些额外的东西:

    • XQuartz必须首先运行:
      $open-a XQuartz
      
    • 您可以公开
      127.0.0.1
      而不是查找您的本地IP(注意:我不是此设置的专家):
      $xhost+127.0.0.1
      127.0.0.1添加到访问控制列表
      
    • 您可以将特殊的
      host.docker.internal
      标识符与
      docker run
      一起使用:
      $docker run-e DISPLAY=host.docker.internal:0 jess/firefox
      
      #2.7.11不适合我(macOS Sierra 10.12.4+Docker CE 17.03.1)。我必须降级到2.7.10u beta2才能工作。xhost在哪里?xhost命令应该在XQuartzI的xterm窗口中输入。2.7.11版也有同样的问题。我卸载了它,并将其降级到2.7.10u beta2,最终一切正常。我只需要重新启动(而不是仅仅注销),事情就开始运转了。我有一个很好的时间来处理这个。。。降级等等。结果证明问题仅仅是重新启动是必要的。现在在XQuartz 2.7.11上完美运行,在MacOS 10.13.3上使用Docker CE 17.12.0版。工作出色。当我将XQuaterz降级到2.7.10_beta2时,它就可以工作了。