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