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