1
yum install docker-ce -y
yum install python-pip -y
pip install docker-compose
systemctl enable docker.service
systemctl start docker.service
docker pull progrium/consul
环境:
192.168.56.11
192.168.56.12
192.168.56.13
目的实现192.168.56.11 自建网络互通
192.168.56.13
docker run -d -p 8500:8500 --name consul progrium/consul -server -bootstrap
192.168.56.11
/usr/lib/systemd/system/docker.service
ExecStart=/usr/bin/dockerd -H tcp://192.168.56.11 -H unix://var/run/docker.sock
[root@linux-node1 ~]# cat /etc/docker/daemon.json
{
  "registry-mirrors": ["http://224ac393.m.daocloud.io"],
  "cluster-store": "consul://192.168.56.13:8500",
  "cluster-advertise": "192.168.56.11:2375"
}
[root@linux-node1 ~]# 
systemctl  daemon-reload
systemctl  restart docker
192.168.56.12
/usr/lib/systemd/system/docker.service
ExecStart=/usr/bin/dockerd -H tcp://192.168.56.12 -H unix://var/run/docker.sock
[root@linux-node1 ~]# cat /etc/docker/daemon.json
{
  "registry-mirrors": ["http://224ac393.m.daocloud.io"],
  "cluster-store": "consul://192.168.56.13:8500",
  "cluster-advertise": "192.168.56.12:2375"
}
[root@linux-node2 ~]# 
systemctl  daemon-reload
systemctl  restart docker
浏览器浏览

测试
192.168.56.11 上面
docker network create -d overlay --subnet 192.168.1.0/24 ov_net1  #192.168.56.12 上面默认就有了 不用创建了
[root@linux-node1 ~]# docker  network ls 
NETWORK ID          NAME                DRIVER              SCOPE
587ebbdc8cf6        bridge              bridge              local
42863825595a        docker_gwbridge     bridge              local
df6484f00517        host                host                local
adf74519830e        none                null                local
e8d259aa8fe3        ov_net1             overlay             global
[root@linux-node1 ~]# 
[root@linux-node2 ~]# docker network  ls 
NETWORK ID          NAME                DRIVER              SCOPE
624c4d1628bd        bridge              bridge              local
4f7d45ab8d94        docker_gwbridge     bridge              local
df6484f00517        host                host                local
adf74519830e        none                null                local
e8d259aa8fe3        ov_net1             overlay             global
[root@linux-node2 ~]# 
192.168.56.11测试
docker run -it --rm --net=ov_net1 busybox
192.168.56.12测试
docker run -it --rm --net=ov_net1 busybox
查看两个容器的IP地址互相ping下 可以ping通
docker run -it --rm --net=ov_net1  --ip=192.168.1.10   busybox  #指定IP地址

Docker overlay网络互通_第1张图片