使用docker overlay网络中的consul在容器之间进行通信时,目标主机无法访问

时间:2017-03-16 14:08:49

标签: docker consul docker-networking

我在centos 7中使用docker 17.03版本

内核版本 - 3.10.0-514.10.2.el7.x86_64

Client:
 Version:      17.03.0-ce
 API version:  1.26
 Go version:   go1.7.5
 Git commit:   3a232c8
 Built:        Tue Feb 28 08:10:07 2017
 OS/Arch:      linux/amd64

Server:
 Version:      17.03.0-ce
 API version:  1.26 (minimum version 1.12)
 Go version:   go1.7.5
 Git commit:   3a232c8
 Built:        Tue Feb 28 08:10:07 2017
 OS/Arch:      linux/amd64
 Experimental: false

我有dock-0和node-1用于docker多主机网络,我正在使用consul。在node-0中,我使用以下命令

创建了一个consul容器
docker run -d -p 8500:8500 -h consul --name consul progrium/consul -server -bootstrap

然后我在/etc/systemd/system/docker.service.d中创建了一个drop-in文件并添加了以下行,

[Service]
ExecStart=
ExecStart=/usr/bin/dockerd -H tcp://0.0.0.0:2375 -H unix:///var/run/docker.sock --cluster-store=consul://<NODE-0-PRIVATE-IP>:8500/network --cluster-advertise=<NODE0-IP>:2375"

一旦完成,我重新启动了docker demon并使用该命令创建了一个覆盖网络, docker network create -d overlay --subnet = 10.10.10.0 / 24 my-net 然后我在node-0中创建了一个名为container1的容器,并将其映射到my-net。

在node-1机器中,我在/etc/systemd/system/docker.service.d中创建了一个插件文件,并添加了以下行,

[Service]
ExecStart=
ExecStart=/usr/bin/dockerd -H tcp://0.0.0.0:2375 -H unix:///var/run/docker.sock --cluster-store=consul://<NODE-0-PRIVATE-IP>:8500/network --cluster-advertise=<NODE1-IP>:2375"

并启动了一个名为container2的容器,并将其映射到my-net。

我的设置看起来像,

node0 - consul, container1
node1 - container2

在container2中,我试图ping容器1但得到以下响应,

PING container1 (10.10.10.3) 56(84) bytes of data.
From container2 (10.10.10.4) icmp_seq=1 Destination Host Unreachable
From container2 (10.10.10.4) icmp_seq=2 Destination Host Unreachable
From container2 (10.10.10.4) icmp_seq=3 Destination Host Unreachable
From container2 (10.10.10.4) icmp_seq=4 Destination Host Unreachable
来自node0的

ip a显示

 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN qlen 1
        link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
        inet 127.0.0.1/8 scope host lo
           valid_lft forever preferred_lft forever
        inet6 ::1/128 scope host
           valid_lft forever preferred_lft forever
    2: ens32: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
        link/ether 00:50:56:9d:9c:9f brd ff:ff:ff:ff:ff:ff
        inet <NODE0-PRIVATE-IP>/24 brd 192.168.5.255 scope global ens32
           valid_lft forever preferred_lft forever
        inet6 fe80::250:56ff:fe9d:9c9f/64 scope link
           valid_lft forever preferred_lft forever
    3: docker0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP
        link/ether 02:42:57:6d:e8:a9 brd ff:ff:ff:ff:ff:ff
        inet 172.17.0.1/16 scope global docker0
           valid_lft forever preferred_lft forever
        inet6 fe80::42:57ff:fe6d:e8a9/64 scope link
           valid_lft forever preferred_lft forever
    4: docker_gwbridge: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP
        link/ether 02:42:10:5b:7d:b5 brd ff:ff:ff:ff:ff:ff
        inet 172.19.0.1/16 scope global docker_gwbridge
           valid_lft forever preferred_lft forever
        inet6 fe80::42:10ff:fe5b:7db5/64 scope link

在container1内,ip a显示为,

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN qlen 1
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
18: eth0@if19: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1450 qdisc noqueue state UP
    link/ether 02:42:0a:0a:0a:03 brd ff:ff:ff:ff:ff:ff link-netnsid 0
    inet 10.10.10.3/24 scope global eth0
       valid_lft forever preferred_lft forever
    inet6 fe80::42:aff:fe0a:a03/64 scope link
       valid_lft forever preferred_lft forever
20: eth1@if21: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP
    link/ether 02:42:ac:13:00:03 brd ff:ff:ff:ff:ff:ff link-netnsid 1
    inet 172.19.0.3/16 scope global eth1
       valid_lft forever preferred_lft forever
    inet6 fe80::42:acff:fe13:3/64 scope link
       valid_lft forever preferred_lft forever

我是否需要更改任何内容才能完成这项工作?提前谢谢。

1 个答案:

答案 0 :(得分:-1)

我在CentOS7上安装了docker 18.09.1,我无法从docker主机ping远程主机,当ping时,我获取了docker配置的docker_gwbridge IP,网络的IP 搜索并找到本文https://github.com/docker/for-mac/issues/2345,在下面运行了命令,并能够ping通远程主机。

docker network rm docker_gwbridge

也许尝试离开人群,然后尝试

docker swarm leave -f