1. 安装好 Swarm
2. 修改 守护进程参数 (红色地方,每台机器设置不同)
DOCKER_OPTS=" --label name=
server-1 -H tcp://0.0.0.0:2375 -H unix:///var/run/docker.sock --cluster-store zk://192.168.6.62/store --cluster-advertise eth0:2376"
3. 创建虚拟网络
docker -H tcp://192.168.124.128:8888 network create -d overlay ovr0
4. 创建容器
docker -H tcp://192.168.124.128:8888 run -d --name m1 --net ovr0 --env="constraint:name==server-1" index.alauda.cn/library/nginx
docker -H tcp://192.168.124.128:8888 run -d --name m2 --net ovr0 --env="constraint:name==server-2" index.alauda.cn/library/nginx
5. 测试
docker exec -it m1
docker network connect ovr0 k1
docker network disconnect ovr0 k1