mirror of https://github.com/docker/docs.git
96 lines
2.6 KiB
Markdown
96 lines
2.6 KiB
Markdown
---
|
|
datafolder: engine-cli
|
|
datafile: docker_service_update
|
|
title: docker service update
|
|
---
|
|
|
|
<!--
|
|
Sorry, but the contents of this page are automatically generated from
|
|
Docker's source code. If you want to suggest a change to the text that appears
|
|
here, you'll need to find the string by searching this repo:
|
|
|
|
https://www.github.com/docker/docker
|
|
-->
|
|
|
|
{% include cli.md %}
|
|
|
|
## Examples
|
|
|
|
### Update a service
|
|
|
|
```bash
|
|
$ 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
|
|
or volumes.
|
|
|
|
The following example creates a service which mounts the `test-data` volume to
|
|
`/somewhere`. The next step updates the service to also mount the `other-volume`
|
|
volume to `/somewhere-else`volume, The last step unmounts the `/somewhere` mount
|
|
point, effectively removing the `test-data` volume. Each command returns the
|
|
service name.
|
|
|
|
- The `--mount-add` flag takes the same parameters as the `--mount` flag on
|
|
`service create`. Refer to the [volumes and
|
|
bind-mounts](service_create.md#volumes-and-bind-mounts-mount) section in the
|
|
`service create` reference for details.
|
|
|
|
- The `--mount-rm` flag takes the `target` path of the mount.
|
|
|
|
```bash
|
|
$ docker service create \
|
|
--name=myservice \
|
|
--mount \
|
|
type=volume,source=test-data,target=/somewhere \
|
|
nginx:alpine \
|
|
myservice
|
|
|
|
myservice
|
|
|
|
$ docker service update \
|
|
--mount-add \
|
|
type=volume,source=other-volume,target=/somewhere-else \
|
|
myservice
|
|
|
|
myservice
|
|
|
|
$ docker service update --mount-rm /somewhere myservice
|
|
|
|
myservice
|
|
```
|
|
|
|
### Adding and removing secrets
|
|
|
|
Use the `--secret-add` or `--secret-rm` options add or remove a service's
|
|
secrets.
|
|
|
|
The following example adds a secret named `ssh-2` and removes `ssh-1`:
|
|
|
|
```bash
|
|
$ docker service update \
|
|
--secret-add source=ssh-2,target=ssh-2 \
|
|
--secret-rm ssh-1 \
|
|
myservice
|
|
```
|
|
|
|
### Update services using templates
|
|
|
|
Some flags of `service update` support the use of templating.
|
|
See [`service create`](./service_create.md#templating) for the reference.
|