一旦你部署了一个服务到swarm集群中,你就可以使用docker命令行来伸缩扩容运行该服务的容器数量。运行在多个容器的一个服务叫做tasks 任务。
$docker machine ssh manager1
$ docker service scale <SERVICE-ID>=<NUMBER-OF-TASKS>
$ docker service scale helloworld=5 helloworld scaled to 5
查看扩容的服务列表:
docker service ps <SERVICE-ID>
$ docker service ps helloworld NAME IMAGE NODE DESIRED STATE CURRENT STATE helloworld.1.8p1vev3fq5zm0mi8g0as41w35 alpine worker2 Running Running 7 minutes helloworld.2.c7a7tcdq5s0uk3qr88mf8xco6 alpine worker1 Running Running 24 seconds helloworld.3.6crl09vdcalvtfehfh69ogfb1 alpine worker1 Running Running 24 seconds helloworld.4.auky6trawmdlcne8ad8phb0f1 alpine manager1 Running Running 24 seconds helloworld.5.ba19kca06l18zujfwxyc5lkyn alpine worker2 Running Running 24 seconds
你可以看到swarm已经创建了4个新的任务,总共扩容到5个运行的实例
这些任务分布在swarm集群的三个节点中。其中一个是运行在manager1中。
在manager1 执行 docker ps
$ docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 528d68040f95 alpine:latest "ping docker.com" About a minute ago Up About a minute helloworld.4.auky6trawmdlcne8ad8phb0f1
本文出自 “清风柳絮” 博客,请务必保留此出处http://binuu.blog.51cto.com/801317/1942371
scale the service in the swarm
原文地址:http://binuu.blog.51cto.com/801317/1942371