github.com/docker/docker-ce@v17.12.1-ce-rc2+incompatible/components/cli/docs/reference/commandline/service_update.md (about) 1 --- 2 title: "service update" 3 description: "The service update command description and usage" 4 keywords: "service, update" 5 --- 6 7 <!-- This file is maintained within the docker/cli GitHub 8 repository at https://github.com/docker/cli/. Make all 9 pull requests against that repo. If you see this file in 10 another repository, consider it read-only there, as it will 11 periodically be overwritten by the definitive file. Pull 12 requests which include edits to this file in other repositories 13 will be rejected. 14 --> 15 16 # service update 17 18 ```Markdown 19 Usage: docker service update [OPTIONS] SERVICE 20 21 Update a service 22 23 Options: 24 --args command Service command args 25 --config-add config Add or update a config file on a service 26 --config-rm list Remove a configuration file 27 --constraint-add list Add or update a placement constraint 28 --constraint-rm list Remove a constraint 29 --container-label-add list Add or update a container label 30 --container-label-rm list Remove a container label by its key 31 --credential-spec credential-spec Credential spec for managed service account (Windows only) 32 -d, --detach Exit immediately instead of waiting for the service to converge (default true) 33 --dns-add list Add or update a custom DNS server 34 --dns-option-add list Add or update a DNS option 35 --dns-option-rm list Remove a DNS option 36 --dns-rm list Remove a custom DNS server 37 --dns-search-add list Add or update a custom DNS search domain 38 --dns-search-rm list Remove a DNS search domain 39 --endpoint-mode string Endpoint mode (vip or dnsrr) 40 --entrypoint command Overwrite the default ENTRYPOINT of the image 41 --env-add list Add or update an environment variable 42 --env-rm list Remove an environment variable 43 --force Force update even if no changes require it 44 --generic-resource-add list Add an additional generic resource to the service's resources requirements 45 --generic-resource-rm list Remove a previously added generic resource to the service's resources requirements 46 --group-add list Add an additional supplementary user group to the container 47 --group-rm list Remove a previously added supplementary user group from the container 48 --health-cmd string Command to run to check health 49 --health-interval duration Time between running the check (ms|s|m|h) 50 --health-retries int Consecutive failures needed to report unhealthy 51 --health-start-period duration Start period for the container to initialize before counting retries towards unstable (ms|s|m|h) 52 --health-timeout duration Maximum time to allow one check to run (ms|s|m|h) 53 --help Print usage 54 --host-add list Add a custom host-to-IP mapping (host:ip) 55 --host-rm list Remove a custom host-to-IP mapping (host:ip) 56 --hostname string Container hostname 57 --image string Service image tag 58 --isolation string Service container isolation mode 59 --label-add list Add or update a service label 60 --label-rm list Remove a label by its key 61 --limit-cpu decimal Limit CPUs 62 --limit-memory bytes Limit Memory 63 --log-driver string Logging driver for service 64 --log-opt list Logging driver options 65 --mount-add mount Add or update a mount on a service 66 --mount-rm list Remove a mount by its target path 67 --network-add network Add a network 68 --network-rm list Remove a network 69 --no-healthcheck Disable any container-specified HEALTHCHECK 70 --no-resolve-image Do not query the registry to resolve image digest and supported platforms 71 --placement-pref-add pref Add a placement preference 72 --placement-pref-rm pref Remove a placement preference 73 --publish-add port Add or update a published port 74 --publish-rm port Remove a published port by its target port 75 -q, --quiet Suppress progress output 76 --read-only Mount the container's root filesystem as read only 77 --replicas uint Number of tasks 78 --reserve-cpu decimal Reserve CPUs 79 --reserve-memory bytes Reserve Memory 80 --restart-condition string Restart when condition is met ("none"|"on-failure"|"any") 81 --restart-delay duration Delay between restart attempts (ns|us|ms|s|m|h) 82 --restart-max-attempts uint Maximum number of restarts before giving up 83 --restart-window duration Window used to evaluate the restart policy (ns|us|ms|s|m|h) 84 --rollback Rollback to previous specification 85 --rollback-delay duration Delay between task rollbacks (ns|us|ms|s|m|h) 86 --rollback-failure-action string Action on rollback failure ("pause"|"continue") 87 --rollback-max-failure-ratio float Failure rate to tolerate during a rollback 88 --rollback-monitor duration Duration after each task rollback to monitor for failure (ns|us|ms|s|m|h) 89 --rollback-order string Rollback order ("start-first"|"stop-first") 90 --rollback-parallelism uint Maximum number of tasks rolled back simultaneously (0 to roll back all at once) 91 --secret-add secret Add or update a secret on a service 92 --secret-rm list Remove a secret 93 --stop-grace-period duration Time to wait before force killing a container (ns|us|ms|s|m|h) 94 --stop-signal string Signal to stop the container 95 -t, --tty Allocate a pseudo-TTY 96 --update-delay duration Delay between updates (ns|us|ms|s|m|h) 97 --update-failure-action string Action on update failure ("pause"|"continue"|"rollback") 98 --update-max-failure-ratio float Failure rate to tolerate during an update 99 --update-monitor duration Duration after each task update to monitor for failure (ns|us|ms|s|m|h) 100 --update-order string Update order ("start-first"|"stop-first") 101 --update-parallelism uint Maximum number of tasks updated simultaneously (0 to update all at once) 102 -u, --user string Username or UID (format: <name|uid>[:<group|gid>]) 103 --with-registry-auth Send registry authentication details to swarm agents 104 -w, --workdir string Working directory inside the container 105 ``` 106 107 ## Description 108 109 Updates a service as described by the specified parameters. This command has to be run targeting a manager node. 110 The parameters are the same as [`docker service create`](service_create.md). Please look at the description there 111 for further information. 112 113 Normally, updating a service will only cause the service's tasks to be replaced with new ones if a change to the 114 service requires recreating the tasks for it to take effect. For example, only changing the 115 `--update-parallelism` setting will not recreate the tasks, because the individual tasks are not affected by this 116 setting. However, the `--force` flag will cause the tasks to be recreated anyway. This can be used to perform a 117 rolling restart without any changes to the service parameters. 118 119 ## Examples 120 121 ### Update a service 122 123 ```bash 124 $ docker service update --limit-cpu 2 redis 125 ``` 126 127 ### Perform a rolling restart with no parameter changes 128 129 ```bash 130 $ docker service update --force --update-parallelism 1 --update-delay 30s redis 131 ``` 132 133 In this example, the `--force` flag causes the service's tasks to be shut down 134 and replaced with new ones even though none of the other parameters would 135 normally cause that to happen. The `--update-parallelism 1` setting ensures 136 that only one task is replaced at a time (this is the default behavior). The 137 `--update-delay 30s` setting introduces a 30 second delay between tasks, so 138 that the rolling restart happens gradually. 139 140 ### Add or remove mounts 141 142 Use the `--mount-add` or `--mount-rm` options add or remove a service's bind mounts 143 or volumes. 144 145 The following example creates a service which mounts the `test-data` volume to 146 `/somewhere`. The next step updates the service to also mount the `other-volume` 147 volume to `/somewhere-else`volume, The last step unmounts the `/somewhere` mount 148 point, effectively removing the `test-data` volume. Each command returns the 149 service name. 150 151 - The `--mount-add` flag takes the same parameters as the `--mount` flag on 152 `service create`. Refer to the [volumes and 153 bind mounts](service_create.md#volumes-and-bind-mounts-mount) section in the 154 `service create` reference for details. 155 156 - The `--mount-rm` flag takes the `target` path of the mount. 157 158 ```bash 159 $ docker service create \ 160 --name=myservice \ 161 --mount \ 162 type=volume,source=test-data,target=/somewhere \ 163 nginx:alpine \ 164 myservice 165 166 myservice 167 168 $ docker service update \ 169 --mount-add \ 170 type=volume,source=other-volume,target=/somewhere-else \ 171 myservice 172 173 myservice 174 175 $ docker service update --mount-rm /somewhere myservice 176 177 myservice 178 ``` 179 180 ### Add or remove published service ports 181 182 Use the `--publish-add` or `--publish-rm` flags to add or remove a published 183 port for a service. You can use the short or long syntax discussed in the 184 [docker service create](service_create/#attach-a-service-to-an-existing-network-network) 185 reference. 186 187 The following example adds a published service port to an existing service. 188 189 ```bash 190 $ docker service update \ 191 --publish-add published=8080,target=80 \ 192 myservice 193 ``` 194 195 ### Roll back to the previous version of a service 196 197 Use the `--rollback` option to roll back to the previous version of the service. 198 199 This will revert the service to the configuration that was in place before the most recent `docker service update` command. 200 201 The following example updates the number of replicas for the service from 4 to 5, and then rolls back to the previous configuration. 202 203 ```bash 204 $ docker service update --replicas=5 web 205 206 web 207 208 $ docker service ls 209 210 ID NAME MODE REPLICAS IMAGE 211 80bvrzp6vxf3 web replicated 0/5 nginx:alpine 212 213 ``` 214 Roll back the `web` service... 215 216 ```bash 217 $ docker service update --rollback web 218 219 web 220 221 $ docker service ls 222 223 ID NAME MODE REPLICAS IMAGE 224 80bvrzp6vxf3 web replicated 0/4 nginx:alpine 225 226 ``` 227 228 Other options can be combined with `--rollback` as well, for example, `--update-delay 0s` to execute the rollback without a delay between tasks: 229 230 ```bash 231 $ docker service update \ 232 --rollback \ 233 --update-delay 0s 234 web 235 236 web 237 238 ``` 239 240 Services can also be set up to roll back to the previous version automatically 241 when an update fails. To set up a service for automatic rollback, use 242 `--update-failure-action=rollback`. A rollback will be triggered if the fraction 243 of the tasks which failed to update successfully exceeds the value given with 244 `--update-max-failure-ratio`. 245 246 The rate, parallelism, and other parameters of a rollback operation are 247 determined by the values passed with the following flags: 248 249 - `--rollback-delay` 250 - `--rollback-failure-action` 251 - `--rollback-max-failure-ratio` 252 - `--rollback-monitor` 253 - `--rollback-parallelism` 254 255 For example, a service set up with `--update-parallelism 1 --rollback-parallelism 3` 256 will update one task at a time during a normal update, but during a rollback, 3 257 tasks at a time will get rolled back. These rollback parameters are respected both 258 during automatic rollbacks and for rollbacks initiated manually using `--rollback`. 259 260 ### Add or remove secrets 261 262 Use the `--secret-add` or `--secret-rm` options add or remove a service's 263 secrets. 264 265 The following example adds a secret named `ssh-2` and removes `ssh-1`: 266 267 ```bash 268 $ docker service update \ 269 --secret-add source=ssh-2,target=ssh-2 \ 270 --secret-rm ssh-1 \ 271 myservice 272 ``` 273 274 ### Update services using templates 275 276 Some flags of `service update` support the use of templating. 277 See [`service create`](./service_create.md#templating) for the reference. 278 279 280 ### Specify isolation mode (Windows) 281 282 `service update` supports the same `--isolation` flag as `service create` 283 See [`service create`](./service_create.md) for the reference. 284 285 ## Related commands 286 287 * [service create](service_create.md) 288 * [service inspect](service_inspect.md) 289 * [service logs](service_logs.md) 290 * [service ls](service_ls.md) 291 * [service ps](service_ps.md) 292 * [service rm](service_rm.md) 293 * [service rollback](service_rollback.md) 294 * [service scale](service_scale.md)