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