在相同的demo网络下容器之间无法ping通name,ip

来源:7-5 集群服务间通信之Routing Mesh

男人花

2021-04-20

环境centos7
docker:Docker version 20.10.5

1.已添加节点如集群

ID                            HOSTNAME    STATUS    AVAILABILITY   MANAGER STATUS   ENGINE VERSION
pdyumk35v7eit9onqpz0z8yo5 *   imooc       Ready     Active         Leader           20.10.5
skbxpln3lq4152j7k7kydj2x3     imooc-197   Ready     Active                          20.10.5
lxt0ro2lpio3gxjlobq4bkojv     imooc-198   Ready     Active                          20.10.5

2创建网络

[root@imooc ~]# docker network ls
NETWORK ID     NAME                  DRIVER    SCOPE
545b2cfa42ab   bridge                bridge    local
tnb2ysbk7zjc   demo                  overlay   swarm
808e45a15949   docker-yapi_default   bridge    local
32f35e034a60   docker_gwbridge       bridge    local
05fde109d316   host                  host      local
rg55aremdea5   ingress               overlay   swarm
f58cf5271285   none                  null      local
3uoqb0k44s3a   over_demo             overlay   swarm
  1. 创建容器
docker service create --name client -d --network demo centos sh -c "while true; do sleep 3600; done"
docker service create --name whoami -p 8000:8000 --network demo -d jwilder/whoami

4.docker service详情

[root@imooc ~]# docker service ls
ID             NAME      MODE         REPLICAS   IMAGE                   PORTS
yy38cr3obbor   client    replicated   1/1        centos:latest           
wk75f606xxha   whoami    replicated   1/1        jwilder/whoami:latest   *:8000->8000/tcp
[root@imooc ~]# docker service ps client whoami
ID             NAME       IMAGE                   NODE        DESIRED STATE   CURRENT STATE            ERROR     PORTS
jegn9pbhp7vx   client.1   centos:latest           imooc-197   Running         Running 12 minutes ago             
jnt5qk21yf9f   whoami.1   jwilder/whoami:latest   imooc       Running         Running 12 minutes ago      

5.docker network inspect tnb2ysbk7zjc(demo网络id)

"Containers": {
            "06c2d73d4f3dce2176f3ff97d2b7cbbbed452c1c83bbf44c015f72b8655e8bfc": {
                "Name": "whoami.1.jnt5qk21yf9fomx7gbdr70xwe",
                "EndpointID": "ec76896da86946edc8f10bec2390f5c975481739d78f38bf467d6aaa255a547d",
                "MacAddress": "02:42:0a:00:02:03",
                "IPv4Address": "10.0.2.3/24",
                "IPv6Address": ""
            },
            "lb-demo": {
                "Name": "demo-endpoint",
                "EndpointID": "6aa73c022f4b22ba199c3a6846576e98a83ede5d7649a01cc5a394e4343c1512",
                "MacAddress": "02:42:0a:00:02:04",
                "IPv4Address": "10.0.2.4/24",
                "IPv6Address": ""
            }
        },

6.进入whoami后ping client无效,ping client ip无效,ping dome网络连通

/app # ping 10.0.2.4
PING 10.0.2.4 (10.0.2.4): 56 data bytes
64 bytes from 10.0.2.4: seq=0 ttl=64 time=0.298 ms
64 bytes from 10.0.2.4: seq=1 ttl=64 time=0.074 ms
64 bytes from 10.0.2.4: seq=2 ttl=64 time=0.077 ms
^C

--- 10.0.2.4 ping statistics ---
3 packets transmitted, 3 packets received, 0% packet loss
round-trip min/avg/max = 0.074/0.149/0.298 ms
/app # ping client
ping: bad address 'client'


/app # ping 10.0.2.6
PING 10.0.2.6 (10.0.2.6): 56 data bytes
^C
--- 10.0.2.6 ping statistics ---
85 packets transmitted, 0 packets received, 100% packet loss
写回答

3回答

麦兜搞IT

2021-04-22

按照docker swarm的文档说法 

TCP and UDP port 7946 for communication among nodes (container network discovery).

多个节点之间网络发现用


0
0

男人花

提问者

2021-04-20

按照自己的想法,猜测是防火墙问题,然后使用netstat -nltp,把两台机器上未开放策略的7946端口打开,ok了,但是不清楚7946端口具体服务的作用是啥?求老师解答

tcp6       0      0 :::8000                 :::*                    LISTEN      1076/dockerd        

tcp6       0      0 :::2377                 :::*                    LISTEN      1076/dockerd        

tcp6       0      0 :::7946                 :::*                    LISTEN      1076/dockerd  


-----------------------------------------------------------------------------------


[root@f3db82155201 /]# ping whoami

PING whoami (10.0.2.2) 56(84) bytes of data.

64 bytes from 10.0.2.2 (10.0.2.2): icmp_seq=1 ttl=64 time=0.422 ms

64 bytes from 10.0.2.2 (10.0.2.2): icmp_seq=2 ttl=64 time=0.030 ms

64 bytes from 10.0.2.2 (10.0.2.2): icmp_seq=3 ttl=64 time=0.056 ms

64 bytes from 10.0.2.2 (10.0.2.2): icmp_seq=2 ttl=64 time=0.030 ms

64 bytes from 10.0.2.2 (10.0.2.2): icmp_seq=3 ttl=64 time=0.056 ms


/app # ping client

PING client (10.0.2.5): 56 data bytes

64 bytes from 10.0.2.5: seq=0 ttl=64 time=0.075 ms

64 bytes from 10.0.2.5: seq=1 ttl=64 time=0.070 ms


0
0

男人花

提问者

2021-04-20

这里的环境搭建是centos7镜像,使用VMware链接克隆出三台虚拟机,进行实验。

0
0

系统学习Docker 践行DevOps理念

无论你是开发、测试还是运维,Docker都是你的必备技能。

3297 学习 · 1895 问题

查看课程