Docker Swarm无法访问其他主机中的服务

tzdcorbm  于 2023-04-20  发布在  Docker
关注(0)|答案(1)|浏览(205)

考虑以下docker堆栈

version: "3.2"

services:
  web1:
    image: nginx
    ports:
      - "8081:80"
    deploy:    
      placement:
        constraints:
          - node.role == manager

  web2:
    image: nginx
    ports:
      - "8082:80"

我可以使用我的浏览器轻松访问这两个服务的地址(http://docker_swarm_manager:8081和http://docker_swarm_node:8082)
但是服务web 1不能访问web2,反之亦然。
Ping工作正常,因此DNS工作正常

root@dfb7b6a65a2e:/# ping web
ping: web: Temporary failure in name resolution
root@dfb7b6a65a2e:/# ping web1
PING web1 (10.0.5.5) 56(84) bytes of data.
64 bytes from 10.0.5.5 (10.0.5.5): icmp_seq=1 ttl=64 time=0.072 ms
64 bytes from 10.0.5.5 (10.0.5.5): icmp_seq=2 ttl=64 time=0.082 ms
...
--- web1 ping statistics ---
7 packets transmitted, 7 received, 0% packet loss, time 6009ms
rtt min/avg/max/mdev = 0.067/0.073/0.082/0.005 ms

但访问服务不起作用

root@dfb7b6a65a2e:/# curl -v web2:80
*   Trying 10.0.5.2:80...
* connect to 10.0.5.2 port 80 failed: Connection timed out
* Failed to connect to web2 port 80: Connection timed out
* Closing connection 0
curl: (28) Failed to connect to web2 port 80: Connection timed out

没有IP/网络冲突,docker swarm使用默认网络,主机使用172.X.X.X/24网络。

yacmzcpb

yacmzcpb1#

Docker swarm运行在虚拟机(vmware)上,vmware使用与Docker相同的端口
vmware docs
Starting with NSX 6.2.3, the default VXLAN port is 4789, the standard port assigned by IANA.
所以解决方案是使用不同的端口重新创建Docker Swarm集群

docker swarm init --data-path-port=7788

Docker swarm docs
Port 4789 UDP (configurable) for the container ingress network.

相关问题