代码之家  ›  专栏  ›  技术社区  ›  Kepboy

无法访问容器内的主机Docker引擎

  •  2
  • Kepboy  · 技术社区  · 8 年前

    简短版本: 如何从windows上的(windows server core)容器中访问docker主机?

    长版本: 我基于microsoft/dotnet framework build:3.5创建了一个映像,用于安装CI/CD过程中使用的工具。

    在构建期间,我安装Chocolate,然后使用choco安装docker CLI客户端。这样我就可以从运行的容器(构建映像)中推送存储在主机上的映像,至少这是我的希望。

    我的问题是,我似乎无法绑定主机 \\.\pipe\docker_engine 到容器中的管道。到目前为止,我已经尝试了以下命令行选项(这些选项会启动交互式测试提示,但正确的构建将是非交互式的)

    docker run --interactive --tty -v \\.\pipe\docker_engine:\\.\pipe\docker_engine my-image
    

    在这种情况下,容器会启动,但绑定不起作用,因为当我运行docker ps时,会出现以下错误:

    error during connect: Get http://%2F%2F.%2Fpipe%2Fdocker_engine/v1.33/version: open //./pipe/docker_engine: message readmode pipes not supported In the default daemon configuration on Windows, the docker client must be run elevated to connect. This error may also indicate that the docker daemon is not running.

    docker run --interactive --tty `
               --mount type=bind,src=\\.\pipe\docker_engine,dst=\\.\pipe\docker_engine `
               my-image
    

    在这种情况下,容器甚至无法启动,因为我得到了以下错误:

    Error response from daemon: invalid mount config for type "bind": source path must be a directory

    如何绑定。\管道\ docker\u引擎,以便容器可以访问主机上的docker引擎?

    我的主机安装的版本信息为:

    Client:
     Version:       17.12.0-ce
     API version:   1.35
     Go version:    go1.9.2
     Git commit:    c97c6d6
     Built: Wed Dec 27 20:05:22 2017
     OS/Arch:       windows/amd64
    
    Server:
     Engine:
      Version:      17.12.0-ce
      API version:  1.35 (minimum version 1.24)
      Go version:   go1.9.2
      Git commit:   c97c6d6
      Built:        Wed Dec 27 20:15:52 2017
      OS/Arch:      windows/amd64
      Experimental: true
    

    容器内的客户端版本信息为

    Client:
     Version:      17.10.0-ce
     API version:  1.33
     Go version:   go1.8.3
     Git commit:   f4ffd25
     Built:        Tue Oct 17 19:00:02 2017
     OS/Arch:      windows/amd64
    
    1 回复  |  直到 8 年前
        1
  •  3
  •   Kepboy    7 年前

    只是为了弥补这个不足

    我能让它工作的唯一方法是向守护进程添加另一个主机。json,主机位于docker nat网络上。所以tcp://nat_network_address:2375

    然后,我设置防火墙规则以允许流量,并在容器内将DOCKER\u HOST环境变量设置为新端点。

    之后,我可以连接到主机docker引擎。

    这并不理想,但在得到适当的修复之前,它可以正常工作。

    Kepboy公司

    更新: 此问题已修复。现在可以在容器中装载名为pipe的主机。

    docker run --interactive --tty -v \\.\pipe\docker_engine:\\.\pipe\docker_engine my-image