github.com/pwn-term/docker@v0.0.0-20210616085119-6e977cce2565/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  # service update
     8  
     9  ```Markdown
    10  Usage:  docker service update [OPTIONS] SERVICE
    11  
    12  Update a service
    13  
    14  Options:
    15        --args command                       Service command args
    16        --cap-add list                       Add Linux capabilities
    17        --cap-drop list                      Drop Linux capabilities
    18        --config-add config                  Add or update a config file on a service
    19        --config-rm list                     Remove a configuration file
    20        --constraint-add list                Add or update a placement constraint
    21        --constraint-rm list                 Remove a constraint
    22        --container-label-add list           Add or update a container label
    23        --container-label-rm list            Remove a container label by its key
    24        --credential-spec credential-spec    Credential spec for managed service account (Windows only)
    25    -d, --detach                             Exit immediately instead of waiting for the service to converge (default true)
    26        --dns-add list                       Add or update a custom DNS server
    27        --dns-option-add list                Add or update a DNS option
    28        --dns-option-rm list                 Remove a DNS option
    29        --dns-rm list                        Remove a custom DNS server
    30        --dns-search-add list                Add or update a custom DNS search domain
    31        --dns-search-rm list                 Remove a DNS search domain
    32        --endpoint-mode string               Endpoint mode (vip or dnsrr)
    33        --entrypoint command                 Overwrite the default ENTRYPOINT of the image
    34        --env-add list                       Add or update an environment variable
    35        --env-rm list                        Remove an environment variable
    36        --force                              Force update even if no changes require it
    37        --generic-resource-add list          Add an additional generic resource to the service's resources requirements
    38        --generic-resource-rm list           Remove a previously added generic resource to the service's resources requirements
    39        --group-add list                     Add an additional supplementary user group to the container
    40        --group-rm list                      Remove a previously added supplementary user group from the container
    41        --health-cmd string                  Command to run to check health
    42        --health-interval duration           Time between running the check (ms|s|m|h)
    43        --health-retries int                 Consecutive failures needed to report unhealthy
    44        --health-start-period duration       Start period for the container to initialize before counting retries towards unstable (ms|s|m|h)
    45        --health-timeout duration            Maximum time to allow one check to run (ms|s|m|h)
    46        --help                               Print usage
    47        --host-add list                      Add a custom host-to-IP mapping (host:ip)
    48        --host-rm list                       Remove a custom host-to-IP mapping (host:ip)
    49        --hostname string                    Container hostname
    50        --init bool                          Use an init inside each service container to forward signals and reap processes
    51        --image string                       Service image tag
    52        --isolation string                   Service container isolation mode
    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        --limit-pids int                     Limit maximum number of processes (default 0 = unlimited)
    58        --log-driver string                  Logging driver for service
    59        --log-opt list                       Logging driver options
    60        --max-concurrent                     Number of job tasks to run at once (default equal to --replicas)
    61        --mount-add mount                    Add or update a mount on a service
    62        --mount-rm list                      Remove a mount by its target path
    63        --network-add network                Add a network
    64        --network-rm list                    Remove a network
    65        --no-healthcheck                     Disable any container-specified HEALTHCHECK
    66        --no-resolve-image                   Do not query the registry to resolve image digest and supported platforms
    67        --placement-pref-add pref            Add a placement preference
    68        --placement-pref-rm pref             Remove a placement preference
    69        --publish-add port                   Add or update a published port
    70        --publish-rm port                    Remove a published port by its target port
    71    -q, --quiet                              Suppress progress output
    72        --read-only                          Mount the container's root filesystem as read only
    73        --replicas uint                      Number of tasks
    74        --reserve-cpu decimal                Reserve CPUs
    75        --reserve-memory bytes               Reserve Memory
    76        --restart-condition string           Restart when condition is met ("none"|"on-failure"|"any")
    77        --restart-delay duration             Delay between restart attempts (ns|us|ms|s|m|h)
    78        --restart-max-attempts uint          Maximum number of restarts before giving up
    79        --restart-window duration            Window used to evaluate the restart policy (ns|us|ms|s|m|h)
    80        --rollback                           Rollback to previous specification
    81        --rollback-delay duration            Delay between task rollbacks (ns|us|ms|s|m|h)
    82        --rollback-failure-action string     Action on rollback failure ("pause"|"continue")
    83        --rollback-max-failure-ratio float   Failure rate to tolerate during a rollback
    84        --rollback-monitor duration          Duration after each task rollback to monitor for failure (ns|us|ms|s|m|h)
    85        --rollback-order string              Rollback order ("start-first"|"stop-first")
    86        --rollback-parallelism uint          Maximum number of tasks rolled back simultaneously (0 to roll back all at once)
    87        --secret-add secret                  Add or update a secret on a service
    88        --secret-rm list                     Remove a secret
    89        --stop-grace-period duration         Time to wait before force killing a container (ns|us|ms|s|m|h)
    90        --stop-signal string                 Signal to stop the container
    91        --sysctl-add list                    Add or update a Sysctl option
    92        --sysctl-rm list                     Remove a Sysctl option
    93    -t, --tty                                Allocate a pseudo-TTY
    94        --ulimit-add ulimit                  Add or update a ulimit option (default [])
    95        --ulimit-rm list                     Remove a ulimit option
    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. The parameters are
   110  the same as [`docker service create`](service_create.md). Refer to the description
   111  there 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  > **Note**
   120  >
   121  > This is a cluster management command, and must be executed on a swarm
   122  > manager node. To learn about managers and workers, refer to the
   123  > [Swarm mode section](https://docs.docker.com/engine/swarm/) in the
   124  > documentation.
   125  
   126  ## Examples
   127  
   128  ### Update a service
   129  
   130  ```bash
   131  $ docker service update --limit-cpu 2 redis
   132  ```
   133  
   134  ### Perform a rolling restart with no parameter changes
   135  
   136  ```bash
   137  $ docker service update --force --update-parallelism 1 --update-delay 30s redis
   138  ```
   139  
   140  In this example, the `--force` flag causes the service's tasks to be shut down
   141  and replaced with new ones even though none of the other parameters would
   142  normally cause that to happen. The `--update-parallelism 1` setting ensures
   143  that only one task is replaced at a time (this is the default behavior). The
   144  `--update-delay 30s` setting introduces a 30 second delay between tasks, so
   145  that the rolling restart happens gradually.
   146  
   147  ### Add or remove mounts
   148  
   149  Use the `--mount-add` or `--mount-rm` options add or remove a service's bind mounts
   150  or volumes.
   151  
   152  The following example creates a service which mounts the `test-data` volume to
   153  `/somewhere`. The next step updates the service to also mount the `other-volume`
   154  volume to `/somewhere-else`volume, The last step unmounts the `/somewhere` mount
   155  point, effectively removing the `test-data` volume. Each command returns the
   156  service name.
   157  
   158  - The `--mount-add` flag takes the same parameters as the `--mount` flag on
   159    `service create`. Refer to the [volumes and bind mounts](service_create.md#add-bind-mounts-volumes-or-memory-filesystems)
   160    section in the `service create` reference for details.
   161  
   162  - The `--mount-rm` flag takes the `target` path of the mount.
   163  
   164  ```bash
   165  $ docker service create \
   166      --name=myservice \
   167      --mount type=volume,source=test-data,target=/somewhere \
   168      nginx:alpine
   169  
   170  myservice
   171  
   172  $ docker service update \
   173      --mount-add 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.md#publish-service-ports-externally-to-the-swarm--p---publish)
   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.md#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#create-services-using-templates) 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  ### Updating Jobs
   305  
   306  When a service is created as a job, by setting its mode to `replicated-job` or
   307  to `global-job` when doing `service create`, options for updating it are
   308  limited.
   309  
   310  Updating a Job immediately stops any Tasks that are in progress. The operation
   311  creates a new set of Tasks for the job and effectively resets its completion
   312  status. If any Tasks were running before the update, they are stopped, and new
   313  Tasks are created.
   314  
   315  Jobs cannot be rolled out or rolled back. None of the flags for configuring
   316  update or rollback settings are valid with job modes.
   317  
   318  To run a job again with the same parameters that it was run previously, it can
   319  be force updated with the `--force` flag.
   320  
   321  ## Related commands
   322  
   323  * [service create](service_create.md)
   324  * [service inspect](service_inspect.md)
   325  * [service logs](service_logs.md)
   326  * [service ls](service_ls.md)
   327  * [service ps](service_ps.md)
   328  * [service rm](service_rm.md)
   329  * [service rollback](service_rollback.md)
   330  * [service scale](service_scale.md)