docker中overlay网络

环境:两台centos7都有docker

consul:10.0.0.13

docker :10.0.0.14

1.修改docker和consul相同的配置文件

[root@test ~]# cat /etc/docker/daemon.json 
{
     "registry-mirrors": ["https://68rmyzg7.mirror.aliyuncs.com"],
      "live-restore":true,
     "hosts":["tcp://0.0.0.0:2376","unix:///var/run/docker.sock"],
     "cluster-store": "consul://10.0.0.13:8500",
     "cluster-advertise": "10.0.0.13:2376"
}

 2.部署consul

-h:设置容器主机名

docker run -d -p 8500:8500 -h consul --name consul --restart=always progrium/consul -server -bootstrap

3. 修改服务启动配置文件

vim /usr/lib/systemd/system/docker.service
将:ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
修改为:ExecStart=/usr/bin/dockerd --containerd=/run/containerd/containerd.sock

4.修改完后重启docker

systemctl daemon-reload
systemctl restart docker

5.查看注册,已经存在两个docker节点了。

http://10.0.0.13:8500/ui/#/dc1/kv/docker/nodes/

6.创建overlay网络

随便一台docker上执行,其他已注册的节点也会创建overlay网络

docker network create --driver overlay --subnet 172.16.1.0/24 --gateway 172.16.1.254 overlay_1

7.创建容器测试

两台分别创建,互相可以ping通

docker run -it --network overlay_1 busybox

  

 

原文地址:https://www.cnblogs.com/zhugq02/p/12864619.html