参考文档:https://docs.docker.com/engine/userguide/networking/get-started-overlay/
https://docs.docker.com/machine/drivers/generic/
1)Step 1: Set up a key-value store
docker-machine create –driver generic –generic-ip-address=192.168.153.222 \
–generic-ssh-key ~/.ssh/id_rsa mh-keystore (要配置无密码登录)
eval “$(docker-machine env mh-keystore)”
docker run -d -p “8500:8500” -h “consul” progrium/consul -server -bootstrap
2)Step 2: Create a Swarm cluster(为避免安装过程中脚本执行docker pull swarm失败,可先在机器上执行docker pull swarm镜像)
docker-machine create \
–driver generic –generic-ip-address=192.168.153.223 \
–generic-ssh-key ~/.ssh/id_rsa \
–swarm –swarm-master \
–swarm-discovery=”consul://
(docker−machineipmh−keystore):8500” –engine−opt=”cluster−store=consul://
(docker-machine ip mh-keystore):8500” \
–engine-opt=”cluster-advertise=eth1:2376” \
mhs-demo0
docker-machine create \
–driver generic –generic-ip-address=192.168.153.225 \
–generic-ssh-key ~/.ssh/id_rsa \
–swarm \
–swarm-discovery=”consul://
(docker−machineipmh−keystore):8500” –engine−opt=”cluster−store=consul://
(docker-machine ip mh-keystore):8500” \
–engine-opt=”cluster-advertise=eth1:2376” \
mhs-demo1
docker-machine ls
3)Step 3: Create the overlay Network
eval $(docker-machine env –swarm mhs-demo0)
docker info
docker network create –driver overlay –subnet=10.0.9.0/24 my-net
4)Step 4: Run an application on your Network
eval $(docker-machine env –swarm mhs-demo0)
docker run -itd –name=web –net=my-net –env=”constraint:node==mhs-demo0” nginx
eval $(docker-machine env mhs-demo1)
注:得先设定node的env,才能执行以下的docker run命令;为了节省时间,先在目标node上docker pull nginx,docker pull busybox
docker run -it –rm –net=my-net –env=”constraint:node==mhs-demo1” busybox wget -O- http://web
5)Step 5: Check external connectivity