所有主、从节点下载镜像
docker pull nginx:1.12

主节点创建swarm
docker swarm init
会提示从节点输入一下命令来加入
docker swarm join --token SWMTKN-1-3hxiorbqg2bwsgcpkmmb00ch85niryn3bed680jge6dbsji6eq-4v8zt90jmh8j2nnzlg5st61er 192.168.56.100:2377

主节点创建服务
docker service create --replicas 3 --name web nginx:1.12

从主节点查看
[root@docker ~]# docker service ls
ID NAME REPLICAS IMAGE COMMAND
0ikn2vly3yaa web 3/3 nginx:1.12

查看具体信息
[root@docker ~]# docker service ps web
ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR
1ppto1xqdwggry1j8sucflxi9 web.1 nginx:1.12 docker1 Running Running 7 minutes ago
6jzmz5dl91yif5wxtb86cphkr web.2 nginx:1.12 docker3 Running Running 10 minutes ago
0swknsfhz5ur0cwny8mh42a8q web.3 nginx:1.12 docker.lmk.com Running Running 11 minutes ago

每个节点重启后都会自动运行docker

将群集节点个数减少到2
docker service scale web=2