1.docker warm 创建应用
docker service create --replicas 1 --name mynginx1 -p 8010:80 192.168.1.11:443/myharbor/nginx:latest
[root@es1 swarm]# docker service create --replicas 1 --name mynginx1 -p 8010:80 192.168.1.11:443/myharbor/nginx:latest
32d752myr4oglzlczmgbviv95
overall progress: 1 out of 1 tasks
1/1: running
verify: Service converged
[root@es1 swarm]# docker service ls
ID NAME MODE REPLICAS IMAGE PORTS
32d752myr4og mynginx1 replicated 1/1 192.168.1.11:443/myharbor/nginx:latest *:8010->80/tcp
[root@es1 swarm]# docker service ps mynginx1
ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR PORTS
em3zv9ge5x69 mynginx1.1 192.168.1.11:443/myharbor/nginx:latest es2 Running Running 52 seconds ago
2.扩容
docker service update --replicas 3 mynginx1
[root@es1 swarm]# docker service update --replicas 3 mynginx1
mynginx1
overall progress: 3 out of 3 tasks
1/3: running
2/3: running
3/3: running
verify: Service converged
[root@es1 swarm]# docker service ls
ID NAME MODE REPLICAS IMAGE PORTS
32d752myr4og mynginx1 replicated 3/3 192.168.1.11:443/myharbor/nginx:latest *:8010->80/tcp
[root@es1 swarm]# docker service ps mynginx1
ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR PORTS
em3zv9ge5x69 mynginx1.1 192.168.1.11:443/myharbor/nginx:latest es2 Running Running about a minute ago
yat0mex8tgm5 mynginx1.2 192.168.1.11:443/myharbor/nginx:latest es1 Running Running 20 seconds ago
btln5sy29htc mynginx1.3 192.168.1.11:443/myharbor/nginx:latest es3 Running Running 20 seconds ago
3.收缩
docker service update --replicas 2 mynginx1
[root@es1 swarm]# docker service update --replicas 2 mynginx1
mynginx1
overall progress: 2 out of 2 tasks
1/2: running
2/2: running
verify: Service converged
[root@es1 swarm]# docker service ls
ID NAME MODE REPLICAS IMAGE PORTS
32d752myr4og mynginx1 replicated 2/2 192.168.1.11:443/myharbor/nginx:latest *:8010->80/tcp
[root@es1 swarm]# docker service ps mynginx1
ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR PORTS
em3zv9ge5x69 mynginx1.1 192.168.1.11:443/myharbor/nginx:latest es2 Running Running 3 minutes ago
yat0mex8tgm5 mynginx1.2 192.168.1.11:443/myharbor/nginx:latest es1 Running Running 2 minutes ago
[root@es1 swarm]# docker service ps -f 'desired-state=running' mynginx1
ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR PORTS
em3zv9ge5x69 mynginx1.1 192.168.1.11:443/myharbor/nginx:latest es2 Running Running 7 minutes ago
yat0mex8tgm5 mynginx1.2 192.168.1.11:443/myharbor/nginx:latest es1 Running Running 5 minutes ago