docker配置

  • /etc/docker/daemon.json
{
    "exec-opts": ["native.cgroupdriver=systemd"],
    "log-driver":"json-file",
    "log-opts": {"max-size":"5m", "max-file":"5"},
    "bip": "10.15.0.1/24", #指定网关地址
  "default-address-pools": [ #定义docker可用的地址池
    {"base": "10.10.0.0/16", "size": 24},
    {"base": "10.20.0.0/16", "size": 24},
    {"base": "10.30.0.0/16", "size": 24},
    {"base": "10.40.0.0/16", "size": 24}
  ]    
}
#sudo systemctl daemon-reload
#sudo systemctl restart docker

创建集群

docker swarm init 
#docker swarm init --default-addr-pool 10.10.0.0/16 --default-addr-pool-mask-length 24

#修改集群网络的子网掩码,删除默认创建的ingress
docker network rm ingress
docker network create --driver overlay --subnet 10.0.0.0/16  ingress
#docker network create --driver overlay --ingress --subnet=10.0.0.0/16 --gateway=10.0.0.1 ingress
#docker network create --driver overlay --ingress --subnet=10.0.0.0/16 --gateway=10.0.0.1   ingress --opt com.docker.network.mtu=1400 ingress

节点加入集群

#查看token
docker swarm join-token worker 
#加入节点
docker swarm join --token SWMTKN-1

创建其它网络

docker network create --driver overlay --subnet 20.10.0.0/16  test1
docker network create --driver overlay --subnet 20.20.0.0/16  test1
docker network create --driver overlay --subnet 20.30.0.0/16  test3
docker network create --driver overlay --subnet 20.40.0.0/16  test4