github.com/AliyunContainerService/cli@v0.0.0-20181009023821-814ced4b30d0/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 --init bool Use an init inside each service container to forward signals and reap processes 58 --image string Service image tag 59 --isolation string Service container isolation mode 60 --label-add list Add or update a service label 61 --label-rm list Remove a label by its key 62 --limit-cpu decimal Limit CPUs 63 --limit-memory bytes Limit Memory 64 --log-driver string Logging driver for service 65 --log-opt list Logging driver options 66 --mount-add mount Add or update a mount on a service 67 --mount-rm list Remove a mount by its target path 68 --network-add network Add a network 69 --network-rm list Remove a network 70 --no-healthcheck Disable any container-specified HEALTHCHECK 71 --no-resolve-image Do not query the registry to resolve image digest and supported platforms 72 --placement-pref-add pref Add a placement preference 73 --placement-pref-rm pref Remove a placement preference 74 --publish-add port Add or update a published port 75 --publish-rm port Remove a published port by its target port 76 -q, --quiet Suppress progress output 77 --read-only Mount the container's root filesystem as read only 78 --replicas uint Number of tasks 79 --reserve-cpu decimal Reserve CPUs 80 --reserve-memory bytes Reserve Memory 81 --restart-condition string Restart when condition is met ("none"|"on-failure"|"any") 82 --restart-delay duration Delay between restart attempts (ns|us|ms|s|m|h) 83 --restart-max-attempts uint Maximum number of restarts before giving up 84 --restart-window duration Window used to evaluate the restart policy (ns|us|ms|s|m|h) 85 --rollback Rollback to previous specification 86 --rollback-delay duration Delay between task rollbacks (ns|us|ms|s|m|h) 87 --rollback-failure-action string Action on rollback failure ("pause"|"continue") 88 --rollback-max-failure-ratio float Failure rate to tolerate during a rollback 89 --rollback-monitor duration Duration after each task rollback to monitor for failure (ns|us|ms|s|m|h) 90 --rollback-order string Rollback order ("start-first"|"stop-first") 91 --rollback-parallelism uint Maximum number of tasks rolled back simultaneously (0 to roll back all at once) 92 --secret-add secret Add or update a secret on a service 93 --secret-rm list Remove a secret 94 --stop-grace-period duration Time to wait before force killing a container (ns|us|ms|s|m|h) 95 --stop-signal string Signal to stop the container 96 -t, --tty Allocate a pseudo-TTY 97 --update-delay duration Delay between updates (ns|us|ms|s|m|h) 98 --update-failure-action string Action on update failure ("pause"|"continue"|"rollback") 99 --update-max-failure-ratio float Failure rate to tolerate during an update 100 --update-monitor duration Duration after each task update to monitor for failure (ns|us|ms|s|m|h) 101 --update-order string Update order ("start-first"|"stop-first") 102 --update-parallelism uint Maximum number of tasks updated simultaneously (0 to update all at once) 103 -u, --user string Username or UID (format: <name|uid>[:<group|gid>]) 104 --with-registry-auth Send registry authentication details to swarm agents 105 -w, --workdir string Working directory inside the container 106 ``` 107 108 ## Description 109 110 Updates a service as described by the specified parameters. This command has to be run targeting a manager node. 111 The parameters are the same as [`docker service create`](service_create.md). Please look at the description there 112 for further information. 113 114 Normally, updating a service will only cause the service's tasks to be replaced with new ones if a change to the 115 service requires recreating the tasks for it to take effect. For example, only changing the 116 `--update-parallelism` setting will not recreate the tasks, because the individual tasks are not affected by this 117 setting. However, the `--force` flag will cause the tasks to be recreated anyway. This can be used to perform a 118 rolling restart without any changes to the service parameters. 119 120 ## Examples 121 122 ### Update a service 123 124 ```bash 125 $ docker service update --limit-cpu 2 redis 126 ``` 127 128 ### Perform a rolling restart with no parameter changes 129 130 ```bash 131 $ docker service update --force --update-parallelism 1 --update-delay 30s redis 132 ``` 133 134 In this example, the `--force` flag causes the service's tasks to be shut down 135 and replaced with new ones even though none of the other parameters would 136 normally cause that to happen. The `--update-parallelism 1` setting ensures 137 that only one task is replaced at a time (this is the default behavior). The 138 `--update-delay 30s` setting introduces a 30 second delay between tasks, so 139 that the rolling restart happens gradually. 140 141 ### Add or remove mounts 142 143 Use the `--mount-add` or `--mount-rm` options add or remove a service's bind mounts 144 or volumes. 145 146 The following example creates a service which mounts the `test-data` volume to 147 `/somewhere`. The next step updates the service to also mount the `other-volume` 148 volume to `/somewhere-else`volume, The last step unmounts the `/somewhere` mount 149 point, effectively removing the `test-data` volume. Each command returns the 150 service name. 151 152 - The `--mount-add` flag takes the same parameters as the `--mount` flag on 153 `service create`. Refer to the [volumes and 154 bind mounts](service_create.md#volumes-and-bind-mounts-mount) section in the 155 `service create` reference for details. 156 157 - The `--mount-rm` flag takes the `target` path of the mount. 158 159 ```bash 160 $ docker service create \ 161 --name=myservice \ 162 --mount \ 163 type=volume,source=test-data,target=/somewhere \ 164 nginx:alpine \ 165 myservice 166 167 myservice 168 169 $ docker service update \ 170 --mount-add \ 171 type=volume,source=other-volume,target=/somewhere-else \ 172 myservice 173 174 myservice 175 176 $ docker service update --mount-rm /somewhere myservice 177 178 myservice 179 ``` 180 181 ### Add or remove published service ports 182 183 Use the `--publish-add` or `--publish-rm` flags to add or remove a published 184 port for a service. You can use the short or long syntax discussed in the 185 [docker service create](service_create/#publish-service-ports-externally-to-the-swarm) 186 reference. 187 188 The following example adds a published service port to an existing service. 189 190 ```bash 191 $ docker service update \ 192 --publish-add published=8080,target=80 \ 193 myservice 194 ``` 195 196 ### Add or remove network 197 198 Use the `--network-add` or `--network-rm` flags to add or remove a network for 199 a service. You can use the short or long syntax discussed in the 200 [docker service create](service_create/#attach-a-service-to-an-existing-network-network) 201 reference. 202 203 The following example adds a new alias name to an existing service already connected to network my-network: 204 205 ```bash 206 $ docker service update \ 207 --network-rm my-network \ 208 --network-add name=my-network,alias=web1 \ 209 myservice 210 ``` 211 212 ### Roll back to the previous version of a service 213 214 Use the `--rollback` option to roll back to the previous version of the service. 215 216 This will revert the service to the configuration that was in place before the most recent `docker service update` command. 217 218 The following example updates the number of replicas for the service from 4 to 5, and then rolls back to the previous configuration. 219 220 ```bash 221 $ docker service update --replicas=5 web 222 223 web 224 225 $ docker service ls 226 227 ID NAME MODE REPLICAS IMAGE 228 80bvrzp6vxf3 web replicated 0/5 nginx:alpine 229 230 ``` 231 Roll back the `web` service... 232 233 ```bash 234 $ docker service update --rollback web 235 236 web 237 238 $ docker service ls 239 240 ID NAME MODE REPLICAS IMAGE 241 80bvrzp6vxf3 web replicated 0/4 nginx:alpine 242 243 ``` 244 245 Other options can be combined with `--rollback` as well, for example, `--update-delay 0s` to execute the rollback without a delay between tasks: 246 247 ```bash 248 $ docker service update \ 249 --rollback \ 250 --update-delay 0s 251 web 252 253 web 254 255 ``` 256 257 Services can also be set up to roll back to the previous version automatically 258 when an update fails. To set up a service for automatic rollback, use 259 `--update-failure-action=rollback`. A rollback will be triggered if the fraction 260 of the tasks which failed to update successfully exceeds the value given with 261 `--update-max-failure-ratio`. 262 263 The rate, parallelism, and other parameters of a rollback operation are 264 determined by the values passed with the following flags: 265 266 - `--rollback-delay` 267 - `--rollback-failure-action` 268 - `--rollback-max-failure-ratio` 269 - `--rollback-monitor` 270 - `--rollback-parallelism` 271 272 For example, a service set up with `--update-parallelism 1 --rollback-parallelism 3` 273 will update one task at a time during a normal update, but during a rollback, 3 274 tasks at a time will get rolled back. These rollback parameters are respected both 275 during automatic rollbacks and for rollbacks initiated manually using `--rollback`. 276 277 ### Add or remove secrets 278 279 Use the `--secret-add` or `--secret-rm` options add or remove a service's 280 secrets. 281 282 The following example adds a secret named `ssh-2` and removes `ssh-1`: 283 284 ```bash 285 $ docker service update \ 286 --secret-add source=ssh-2,target=ssh-2 \ 287 --secret-rm ssh-1 \ 288 myservice 289 ``` 290 291 ### Update services using templates 292 293 Some flags of `service update` support the use of templating. 294 See [`service create`](./service_create.md#templating) for the reference. 295 296 297 ### Specify isolation mode (Windows) 298 299 `service update` supports the same `--isolation` flag as `service create` 300 See [`service create`](./service_create.md) for the reference. 301 302 ## Related commands 303 304 * [service create](service_create.md) 305 * [service inspect](service_inspect.md) 306 * [service logs](service_logs.md) 307 * [service ls](service_ls.md) 308 * [service ps](service_ps.md) 309 * [service rm](service_rm.md) 310 * [service rollback](service_rollback.md) 311 * [service scale](service_scale.md)