2016-06-17 19:51:17 -04:00
|
|
|
# service scale
|
|
|
|
|
2023-01-06 13:04:05 -05:00
|
|
|
<!---MARKER_GEN_START-->
|
2016-11-02 03:53:18 -04:00
|
|
|
Scale one or multiple replicated services
|
2016-06-17 19:51:17 -04:00
|
|
|
|
2023-01-06 13:04:05 -05:00
|
|
|
### Options
|
|
|
|
|
2024-07-03 02:29:57 -04:00
|
|
|
| Name | Type | Default | Description |
|
|
|
|
|:-----------------|:-------|:--------|:----------------------------------------------------------------|
|
|
|
|
| `-d`, `--detach` | `bool` | | Exit immediately instead of waiting for the service to converge |
|
2023-01-06 13:04:05 -05:00
|
|
|
|
|
|
|
|
|
|
|
<!---MARKER_GEN_END-->
|
2016-06-17 19:51:17 -04:00
|
|
|
|
2017-02-07 18:42:48 -05:00
|
|
|
## Description
|
2016-06-17 19:51:17 -04:00
|
|
|
|
2016-11-03 14:20:53 -04:00
|
|
|
The scale command enables you to scale one or more replicated services either up
|
2016-12-14 06:30:09 -05:00
|
|
|
or down to the desired number of replicas. This command cannot be applied on
|
2016-11-02 03:53:18 -04:00
|
|
|
services which are global mode. The command will return immediately, but the
|
2016-10-19 13:25:45 -04:00
|
|
|
actual scaling of the service may take some time. To stop all replicas of a
|
|
|
|
service while keeping the service active in the swarm you can set the scale to 0.
|
2016-06-17 19:51:17 -04:00
|
|
|
|
2024-08-16 05:02:10 -04:00
|
|
|
> [!NOTE]
|
2020-04-19 11:08:37 -04:00
|
|
|
> This is a cluster management command, and must be executed on a swarm
|
|
|
|
> manager node. To learn about managers and workers, refer to the
|
|
|
|
> [Swarm mode section](https://docs.docker.com/engine/swarm/) in the
|
|
|
|
> documentation.
|
2018-12-23 06:27:52 -05:00
|
|
|
|
2017-02-07 18:42:48 -05:00
|
|
|
## Examples
|
|
|
|
|
|
|
|
### Scale a single service
|
|
|
|
|
|
|
|
The following command scales the "frontend" service to 50 tasks.
|
2016-06-17 19:51:17 -04:00
|
|
|
|
2021-08-21 08:54:14 -04:00
|
|
|
```console
|
2016-06-17 19:51:17 -04:00
|
|
|
$ docker service scale frontend=50
|
2017-02-07 18:42:48 -05:00
|
|
|
|
2016-06-17 19:51:17 -04:00
|
|
|
frontend scaled to 50
|
|
|
|
```
|
|
|
|
|
2016-11-02 03:53:18 -04:00
|
|
|
The following command tries to scale a global service to 10 tasks and returns an error.
|
|
|
|
|
2021-08-21 08:54:14 -04:00
|
|
|
```console
|
2016-11-02 03:53:18 -04:00
|
|
|
$ docker service create --mode global --name backend backend:latest
|
2017-02-07 18:42:48 -05:00
|
|
|
|
2016-11-02 03:53:18 -04:00
|
|
|
b4g08uwuairexjub6ome6usqh
|
2017-02-07 18:42:48 -05:00
|
|
|
|
2016-11-02 03:53:18 -04:00
|
|
|
$ docker service scale backend=10
|
2017-02-07 18:42:48 -05:00
|
|
|
|
2020-01-09 13:17:43 -05:00
|
|
|
backend: scale can only be used with replicated or replicated-job mode
|
2016-11-02 03:53:18 -04:00
|
|
|
```
|
|
|
|
|
2016-06-17 19:51:17 -04:00
|
|
|
Directly afterwards, run `docker service ls`, to see the actual number of
|
2016-10-19 13:25:45 -04:00
|
|
|
replicas.
|
2016-06-17 19:51:17 -04:00
|
|
|
|
2021-08-21 08:54:14 -04:00
|
|
|
```console
|
2016-06-17 19:51:17 -04:00
|
|
|
$ docker service ls --filter name=frontend
|
|
|
|
|
2016-10-24 23:39:53 -04:00
|
|
|
ID NAME MODE REPLICAS IMAGE
|
|
|
|
3pr5mlvu3fh9 frontend replicated 15/50 nginx:alpine
|
2016-06-17 19:51:17 -04:00
|
|
|
```
|
|
|
|
|
|
|
|
You can also scale a service using the [`docker service update`](service_update.md)
|
2016-10-19 13:25:45 -04:00
|
|
|
command. The following commands are equivalent:
|
2016-06-17 19:51:17 -04:00
|
|
|
|
2021-08-21 08:54:14 -04:00
|
|
|
```console
|
2016-06-17 19:51:17 -04:00
|
|
|
$ docker service scale frontend=50
|
|
|
|
$ docker service update --replicas=50 frontend
|
|
|
|
```
|
|
|
|
|
|
|
|
### Scale multiple services
|
|
|
|
|
|
|
|
The `docker service scale` command allows you to set the desired number of
|
|
|
|
tasks for multiple services at once. The following example scales both the
|
|
|
|
backend and frontend services:
|
|
|
|
|
2021-08-21 08:54:14 -04:00
|
|
|
```console
|
2016-06-17 19:51:17 -04:00
|
|
|
$ docker service scale backend=3 frontend=5
|
2017-02-07 18:42:48 -05:00
|
|
|
|
2016-06-17 19:51:17 -04:00
|
|
|
backend scaled to 3
|
|
|
|
frontend scaled to 5
|
|
|
|
|
|
|
|
$ docker service ls
|
2017-02-07 18:42:48 -05:00
|
|
|
|
2016-10-24 23:39:53 -04:00
|
|
|
ID NAME MODE REPLICAS IMAGE
|
|
|
|
3pr5mlvu3fh9 frontend replicated 5/5 nginx:alpine
|
2024-11-05 05:20:17 -05:00
|
|
|
74nzcxxjv6fq backend replicated 3/3 redis:7.4.1
|
2016-06-17 19:51:17 -04:00
|
|
|
```
|
|
|
|
|
2017-02-07 18:42:48 -05:00
|
|
|
## Related commands
|
2016-06-17 19:51:17 -04:00
|
|
|
|
|
|
|
* [service create](service_create.md)
|
|
|
|
* [service inspect](service_inspect.md)
|
2016-12-14 06:30:09 -05:00
|
|
|
* [service logs](service_logs.md)
|
2016-06-17 19:51:17 -04:00
|
|
|
* [service ls](service_ls.md)
|
|
|
|
* [service rm](service_rm.md)
|
2017-07-20 04:32:51 -04:00
|
|
|
* [service rollback](service_rollback.md)
|
2016-07-19 17:01:31 -04:00
|
|
|
* [service ps](service_ps.md)
|
2016-06-17 19:51:17 -04:00
|
|
|
* [service update](service_update.md)
|