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