Add force option to service update

Currently, there's no way to restart the tasks of a service without
making an actual change to the service. This leads to us giving awkward
workarounds as in
https://github.com/docker/docker.github.io/pull/178/files, where we tell
people to scale a service up and down to restore balance, or make
unnecessary changes to trigger a restart.

This change adds a --force option to "docker service update", which
forces the service to be updated even if no changes require that.

Since rolling update parameters are respected, the user can use
"docker service --force" to do a rolling restart. For example, the
following is supported:

   docker service update --force --update-parallelism 2 \
   --update-delay 5s myservice

Since the default value of --update-parallelism is 1, the default
behavior is to restart the service one task at a time.

Signed-off-by: Aaron Lehmann <aaron.lehmann@docker.com>
This commit is contained in:
Aaron Lehmann 2016-10-20 12:04:01 -07:00 committed by Tibor Vass
parent f18c41ee83
commit 78c0d50c9f
3 changed files with 22 additions and 0 deletions

View File

@ -2473,6 +2473,7 @@ _docker_service_update() {
--constraint
--endpoint-mode
--env -e
--force
--group-add
--label -l
--limit-cpu

View File

@ -1185,6 +1185,7 @@ __docker_service_subcommand() {
"($help)--arg=[Service command args]:arguments: _normal" \
"($help)*--container-label-add=[Add or update container labels]:label: " \
"($help)*--container-label-rm=[Remove a container label by its key]:label: " \
"($help)--force[Force update]" \
"($help)*--group-rm=[Remove previously added user groups from the container]:group:_groups" \
"($help)--image=[Service image tag]:image:__docker_repositories" \
"($help)--rollback[Rollback to previous specification]" \

View File

@ -29,6 +29,7 @@ Options:
--endpoint-mode string Endpoint mode (vip or dnsrr)
--env-add value Add or update environment variables (default [])
--env-rm value Remove an environment variable (default [])
--force Force update even if no changes require it
--group-add value Add additional user groups to the container (default [])
--group-rm value Remove previously added user groups from the container (default [])
--help Print usage
@ -67,6 +68,12 @@ Updates a service as described by the specified parameters. This command has to
The parameters are the same as [`docker service create`](service_create.md). Please look at the description there
for further information.
Normally, updating a service will only cause the service's tasks to be replaced with new ones if a change to the
service requires recreating the tasks for it to take effect. For example, only changing the
`--update-parallelism` setting will not recreate the tasks, because the individual tasks are not affected by this
setting. However, the `--force` flag will cause the tasks to be recreated anyway. This can be used to perform a
rolling restart without any changes to the service parameters.
## Examples
### Update a service
@ -75,6 +82,19 @@ for further information.
$ docker service update --limit-cpu 2 redis
```
### Perform a rolling restart with no parameter changes
```bash
$ docker service update --force --update-parallelism 1 --update-delay 30s redis
```
In this example, the `--force` flag causes the service's tasks to be shut down
and replaced with new ones even though none of the other parameters would
normally cause that to happen. The `--update-parallelism 1` setting ensures
that only one task is replaced at a time (this is the default behavior). The
`--update-delay 30s` setting introduces a 30 second delay between tasks, so
that the rolling restart happens gradually.
### Adding and removing mounts
Use the `--mount-add` or `--mount-rm` options add or remove a service's bind-mounts