无法从主机 docker 访问 windows 堆栈的容器 IP

Can't access container IP from host docker for windows stack

我正在使用以下 docker 组合文件来构建我的 docker 集群堆栈,其中 windows 容器部署在 Windows 10 中:

version: '3.2'

services:
  service1:
    image: myrepository/dotnet-framework:3.5-windowsservercore
    environment:
      - my_path="C:/app/build/app.exe"
      - my_arg= 1
    deploy:
      replicas: 1
      placement:
        constraints:
          - node.id == asdfasdgasgasg
    volumes:
      - service1:C:/app
  service1:
    image: myrepository/dotnet-framework:3.5-windowsservercore
    ports:
      - target: 7878
        published: 7878
        mode: host
    environment:
      - my_path="C:/app/app.exe"
      - my_arg= 2
    deploy:
      replicas: 1
      placement:
        constraints:
          - node.id == asdfasdgasgasg
    volumes:
      - service1:C:/app

volumes:
  service2:
    external:
      name: service1
  service1:
    external:
      name: service1

如您所见,service2 正在侦听端口 7878。我知道,如 this post 所示,我无法使用 localhost:7878 到达此端口。因此我 运行 命令 docker inspect containerID 找出容器的 IP 地址。

如果我从 service1 ping 容器 service2,它会响应。但是,如果我尝试从主机访问端口 10.0.3.18:7878,则没有任何响应。我怎样才能从热点到达端口 7878?另一方面,我有 Linux 个容器必须到达 'service2' windows 个容器。

默认情况下,服务中的每个 docker 容器都可以相互通信,因为它们是在自己的专用网络上启动的。这就是为什么您可以在服务容器之间 ping 通。

您打开的端口 7878 也可以通过 host windows 10 os 机器的 ip 地址而不是容器访问 host os IP地址。容器的 IP 地址甚至对 hostos.

也是私有的

ping不通可能是因为您没有在服务中打开ping端口,镜像中可能没有ping服务响应您的ping请求。最后一点我可能是错的。 Ping 不是验证容器是否正常工作的好方法。

Windows 已更新,一切正常。