docker-Overlay原生网络
节点1/键值存储:192.168.50.130
节点2:192.168.50.131
1.下载Consul二进制包并启动
wget https://releases.hashicorp.com/consul/0.9.2/consul_0.9.2_linux_amd64.zip
unzip consul_0.9.2_linux_amd64.zipmv consul /usr/bin/consul && chmod +x /usr/bin/consul
nohup consul agent -server -bootstrap -ui -data-dir /var/lib/consul -client=192.168.50.130 -bind=192.168.50.130
&>/var/log/consul.log &
2.节点配置Docker守护进程连接Consul
vi /lib/systemd/system/docker.service
[Service]
ExecStart=/usr/bin/dockerd -H tcp://0.0.0.0:2375 -H unix:///var/run/docker.sock --cluster-store
consul://192.168.50.130:8500 --cluster-advertise 192.168.1.130:2375
systemctl restart docker
3.创建overlay网络
docker network create -d overlay multi_host
4.测试互通
docker run -itd --net=multi_host busybox
节点B:192.168.50.131
1.启动docker:
Systemctl start docker
2.修改配置文件:vim /usr/lib/systemd/system/docker.service
-H tcp://0.0.0.0:2375 -H unix:///var/run/docker.sock --cluster-store consul:// 192.168.50.131:8500 --cluster-advertise 192.168.50.131:2375
systemctl daemon-reload && systemctl restart docker
就可以在consul ui上面看到新增加的节点了
3.创建overlay网络:
docker network create -d overlay multi_host(只要在一个节点创建,就会同步到其他节点,不需要在配置其他节点)
4.测试互通:
A B节点都启动一个容器
docker run -it --rm=true --net=multi_host mydockerfile /bin/bash
ping overlay分配的网络