1. 程式人生 > >scale the service in the swarm

scale the service in the swarm

docker swarm

一旦你部署了一個服務到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