---
title: "Update a service"
method: POST
path: "/services/{id}/update"
tags: ["Service"]
---

# Update a service

`POST /services/{id}/update`

## Path parameters

- `id` string, required

## Query parameters

- `version` integer, required
- `registryAuthFrom` 'spec' | 'previous-spec'
- `rollback` string

## Headers

- `X-Registry-Auth` string

## Request body

- object — User modifiable configuration for a service.
  - `Name` string — Name of the service.
  - `Labels` object — User-defined key/value metadata.
  - `TaskTemplate` TaskSpec — User modifiable task configuration.
    - `PluginSpec` object — Plugin spec for the service. *(Experimental release only.)* <p><br /></p> > **Note**: ContainerSpec, NetworkAttachmentSpec, and PluginSpec are > mutually exclusive. PluginSpec is only used when the Runtime field > is set to `plugin`. NetworkAttachmentSpec is used when the Runtime > field is set to `attachment`.
      - `Name` string — The name or 'alias' to use for the plugin.
      - `Remote` string — The plugin image reference to use.
      - `Disabled` boolean — Disable the plugin once scheduled.
      - `PluginPrivilege` PluginPrivilege[]
        - `Name` string
        - `Description` string
        - `Value` string[]
    - `ContainerSpec` object — Container spec for the service. <p><br /></p> > **Note**: ContainerSpec, NetworkAttachmentSpec, and PluginSpec are > mutually exclusive. PluginSpec is only used when the Runtime field > is set to `plugin`. NetworkAttachmentSpec is used when the Runtime > field is set to `attachment`.
      - `Image` string — The image name to use for the container
      - `Labels` object — User-defined key/value data.
      - `Command` string[] — The command to be run in the image.
      - `Args` string[] — Arguments to the command.
      - `Hostname` string — The hostname to use for the container, as a valid [RFC 1123](https://tools.ietf.org/html/rfc1123) hostname.
      - `Env` string[] — A list of environment variables in the form `VAR=value`.
      - `Dir` string — The working directory for commands to run in.
      - `User` string — The user inside the container.
      - `Groups` string[] — A list of additional groups that the container process will run as.
      - `Privileges` object — Security options for the container
        - `CredentialSpec` object — CredentialSpec for managed service account (Windows only)
          - `Config` string — Load credential spec from a Swarm Config with the given ID. The specified config must also be present in the Configs field with the Runtime property set. <p><br /></p> > **Note**: `CredentialSpec.File`, `CredentialSpec.Registry`, > and `CredentialSpec.Config` are mutually exclusive.
          - `File` string — Load credential spec from this file. The file is read by the daemon, and must be present in the `CredentialSpecs` subdirectory in the docker data directory, which defaults to `C:\ProgramData\Docker\` on Windows. For example, specifying `spec.json` loads `C:\ProgramData\Docker\CredentialSpecs\spec.json`. <p><br /></p> > **Note**: `CredentialSpec.File`, `CredentialSpec.Registry`, > and `CredentialSpec.Config` are mutually exclusive.
          - `Registry` string — Load credential spec from this value in the Windows registry. The specified registry value must be located in: `HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Virtualization\Containers\CredentialSpecs` <p><br /></p> > **Note**: `CredentialSpec.File`, `CredentialSpec.Registry`, > and `CredentialSpec.Config` are mutually exclusive.
        - `SELinuxContext` object — SELinux labels of the container
          - `Disable` boolean — Disable SELinux
          - `User` string — SELinux user label
          - `Role` string — SELinux role label
          - `Type` string — SELinux type label
          - `Level` string — SELinux level label
      - `TTY` boolean — Whether a pseudo-TTY should be allocated.
      - `OpenStdin` boolean — Open `stdin`
      - `ReadOnly` boolean — Mount the container's root filesystem as read only.
      - `Mounts` Mount[] — Specification for mounts to be added to containers created as part of the service.
        - `Target` string — Container path.
        - `Source` string — Mount source (e.g. a volume name, a host path).
        - `Type` 'bind' | 'volume' | 'tmpfs' | 'npipe' | 'cluster' — The mount type. Available types: - `bind` Mounts a file or directory from the host into the container. Must exist prior to creating the container. - `volume` Creates a volume with the given name and options (or uses a pre-existing volume with the same name and options). These are **not** removed when the container is removed. - `tmpfs` Create a tmpfs with the given options. The mount source cannot be specified for tmpfs. - `npipe` Mounts a named pipe from the host into the container. Must exist prior to creating the container. - `cluster` a Swarm cluster volume
        - `ReadOnly` boolean — Whether the mount should be read-only.
        - `Consistency` string — The consistency requirement for the mount: `default`, `consistent`, `cached`, or `delegated`.
        - `BindOptions` object — Optional configuration for the `bind` type.
          - `Propagation` 'private' | 'rprivate' | 'shared' | 'rshared' | 'slave' | 'rslave' — A propagation mode with the value `[r]private`, `[r]shared`, or `[r]slave`.
          - `NonRecursive` boolean — Disable recursive bind mount.
          - `CreateMountpoint` boolean — Create mount point on host if missing
        - `VolumeOptions` object — Optional configuration for the `volume` type.
          - `NoCopy` boolean — Populate volume with data from the target.
          - `Labels` object — User-defined key/value metadata.
          - `DriverConfig` object — Map of driver specific options
            - `Name` string — Name of the driver to use to create the volume.
            - `Options` object — key/value map of driver specific options.
        - `TmpfsOptions` object — Optional configuration for the `tmpfs` type.
          - `SizeBytes` integer — The size for the tmpfs mount in bytes.
          - `Mode` integer — The permission mode for the tmpfs mount in an integer.
      - `StopSignal` string — Signal to stop the container.
      - `StopGracePeriod` integer — Amount of time to wait for the container to terminate before forcefully killing it.
      - `HealthCheck` HealthConfig — A test to perform to check that the container is healthy.
        - `Test` string[] — The test to perform. Possible values are: - `[]` inherit healthcheck from image or parent image - `["NONE"]` disable healthcheck - `["CMD", args...]` exec arguments directly - `["CMD-SHELL", command]` run command with system's default shell
        - `Interval` integer — The time to wait between checks in nanoseconds. It should be 0 or at least 1000000 (1 ms). 0 means inherit.
        - `Timeout` integer — The time to wait before considering the check to have hung. It should be 0 or at least 1000000 (1 ms). 0 means inherit.
        - `Retries` integer — The number of consecutive failures needed to consider a container as unhealthy. 0 means inherit.
        - `StartPeriod` integer — Start period for the container to initialize before starting health-retries countdown in nanoseconds. It should be 0 or at least 1000000 (1 ms). 0 means inherit.
      - `Hosts` string[] — A list of hostname/IP mappings to add to the container's `hosts` file. The format of extra hosts is specified in the [hosts(5)](http://man7.org/linux/man-pages/man5/hosts.5.html) man page: IP_address canonical_hostname [aliases...]
      - `DNSConfig` object — Specification for DNS related configurations in resolver configuration file (`resolv.conf`).
        - `Nameservers` string[] — The IP addresses of the name servers.
        - `Search` string[] — A search list for host-name lookup.
        - `Options` string[] — A list of internal resolver variables to be modified (e.g., `debug`, `ndots:3`, etc.).
      - `Secrets` object[] — Secrets contains references to zero or more secrets that will be exposed to the service.
        - `File` object — File represents a specific target that is backed by a file.
          - `Name` string — Name represents the final filename in the filesystem.
          - `UID` string — UID represents the file UID.
          - `GID` string — GID represents the file GID.
          - `Mode` integer — Mode represents the FileMode of the file.
        - `SecretID` string — SecretID represents the ID of the specific secret that we're referencing.
        - `SecretName` string — SecretName is the name of the secret that this references, but this is just provided for lookup/display purposes. The secret in the reference will be identified by its ID.
      - `Configs` object[] — Configs contains references to zero or more configs that will be exposed to the service.
        - `File` object — File represents a specific target that is backed by a file. <p><br /><p> > **Note**: `Configs.File` and `Configs.Runtime` are mutually exclusive
          - `Name` string — Name represents the final filename in the filesystem.
          - `UID` string — UID represents the file UID.
          - `GID` string — GID represents the file GID.
          - `Mode` integer — Mode represents the FileMode of the file.
        - `Runtime` object — Runtime represents a target that is not mounted into the container but is used by the task <p><br /><p> > **Note**: `Configs.File` and `Configs.Runtime` are mutually > exclusive
        - `ConfigID` string — ConfigID represents the ID of the specific config that we're referencing.
        - `ConfigName` string — ConfigName is the name of the config that this references, but this is just provided for lookup/display purposes. The config in the reference will be identified by its ID.
      - `Isolation` 'default' | 'process' | 'hyperv' — Isolation technology of the containers running the service. (Windows only)
      - `Init` boolean, nullable — Run an init inside the container that forwards signals and reaps processes. This field is omitted if empty, and the default (as configured on the daemon) is used.
      - `Sysctls` object — Set kernel namedspaced parameters (sysctls) in the container. The Sysctls option on services accepts the same sysctls as the are supported on containers. Note that while the same sysctls are supported, no guarantees or checks are made about their suitability for a clustered environment, and it's up to the user to determine whether a given sysctl will work properly in a Service.
      - `CapabilityAdd` string[] — A list of kernel capabilities to add to the default set for the container.
      - `CapabilityDrop` string[] — A list of kernel capabilities to drop from the default set for the container.
      - `Ulimits` object[] — A list of resource limits to set in the container. For example: `{"Name": "nofile", "Soft": 1024, "Hard": 2048}`"
        - `Name` string — Name of ulimit
        - `Soft` integer — Soft limit
        - `Hard` integer — Hard limit
    - `NetworkAttachmentSpec` object — Read-only spec type for non-swarm containers attached to swarm overlay networks. <p><br /></p> > **Note**: ContainerSpec, NetworkAttachmentSpec, and PluginSpec are > mutually exclusive. PluginSpec is only used when the Runtime field > is set to `plugin`. NetworkAttachmentSpec is used when the Runtime > field is set to `attachment`.
      - `ContainerID` string — ID of the container represented by this task
    - `Resources` object — Resource requirements which apply to each individual container created as part of the service.
      - `Limits` Limit — An object describing a limit on resources which can be requested by a task.
        - `NanoCPUs` integer
        - `MemoryBytes` integer
        - `Pids` integer — Limits the maximum number of PIDs in the container. Set `0` for unlimited.
      - `Reservations` ResourceObject — An object describing the resources which can be advertised by a node and requested by a task.
        - `NanoCPUs` integer
        - `MemoryBytes` integer
        - `GenericResources` object[] — User-defined resources can be either Integer resources (e.g, `SSD=3`) or String resources (e.g, `GPU=UUID1`).
          - `NamedResourceSpec` object
            - `Kind` string
            - `Value` string
          - `DiscreteResourceSpec` object
            - `Kind` string
            - `Value` integer
    - `RestartPolicy` object — Specification for the restart policy which applies to containers created as part of this service.
      - `Condition` 'none' | 'on-failure' | 'any' — Condition for restart.
      - `Delay` integer — Delay between restart attempts.
      - `MaxAttempts` integer — Maximum attempts to restart a given container before giving up (default value is 0, which is ignored).
      - `Window` integer — Windows is the time window used to evaluate the restart policy (default value is 0, which is unbounded).
    - `Placement` object
      - `Constraints` string[] — An array of constraint expressions to limit the set of nodes where a task can be scheduled. Constraint expressions can either use a _match_ (`==`) or _exclude_ (`!=`) rule. Multiple constraints find nodes that satisfy every expression (AND match). Constraints can match node or Docker Engine labels as follows: node attribute | matches | example ---------------------|--------------------------------|----------------------------------------------- `node.id` | Node ID | `node.id==2ivku8v2gvtg4` `node.hostname` | Node hostname | `node.hostname!=node-2` `node.role` | Node role (`manager`/`worker`) | `node.role==manager` `node.platform.os` | Node operating system | `node.platform.os==windows` `node.platform.arch` | Node architecture | `node.platform.arch==x86_64` `node.labels` | User-defined node labels | `node.labels.security==high` `engine.labels` | Docker Engine's labels | `engine.labels.operatingsystem==ubuntu-14.04` `engine.labels` apply to Docker Engine labels like operating system, drivers, etc. Swarm administrators add `node.labels` for operational purposes by using the [`node update endpoint`](#operation/NodeUpdate).
      - `Preferences` object[] — Preferences provide a way to make the scheduler aware of factors such as topology. They are provided in order from highest to lowest precedence.
        - `Spread` object
          - `SpreadDescriptor` string — label descriptor, such as `engine.labels.az`.
      - `MaxReplicas` integer — Maximum number of replicas for per node (default value is 0, which is unlimited)
      - `Platforms` Platform[] — Platforms stores all the platforms that the service's image can run on. This field is used in the platform filter for scheduling. If empty, then the platform filter is off, meaning there are no scheduling restrictions.
        - `Architecture` string — Architecture represents the hardware architecture (for example, `x86_64`).
        - `OS` string — OS represents the Operating System (for example, `linux` or `windows`).
    - `ForceUpdate` integer — A counter that triggers an update even if no relevant parameters have been changed.
    - `Runtime` string — Runtime is the type of runtime specified for the task executor.
    - `Networks` NetworkAttachmentConfig[] — Specifies which networks the service should attach to.
      - `Target` string — The target network for attachment. Must be a network name or ID.
      - `Aliases` string[] — Discoverable alternate names for the service on this network.
      - `DriverOpts` object — Driver attachment options for the network target.
    - `LogDriver` object — Specifies the log driver to use for tasks created from this spec. If not present, the default one for the swarm will be used, finally falling back to the engine default if not specified.
      - `Name` string
      - `Options` object
  - `Mode` object — Scheduling mode for the service.
    - `Replicated` object
      - `Replicas` integer
    - `Global` object
    - `ReplicatedJob` object — The mode used for services with a finite number of tasks that run to a completed state.
      - `MaxConcurrent` integer — The maximum number of replicas to run simultaneously.
      - `TotalCompletions` integer — The total number of replicas desired to reach the Completed state. If unset, will default to the value of `MaxConcurrent`
    - `GlobalJob` object — The mode used for services which run a task to the completed state on each valid node.
  - `UpdateConfig` object — Specification for the update strategy of the service.
    - `Parallelism` integer — Maximum number of tasks to be updated in one iteration (0 means unlimited parallelism).
    - `Delay` integer — Amount of time between updates, in nanoseconds.
    - `FailureAction` 'continue' | 'pause' | 'rollback' — Action to take if an updated task fails to run, or stops running during the update.
    - `Monitor` integer — Amount of time to monitor each updated task for failures, in nanoseconds.
    - `MaxFailureRatio` number — The fraction of tasks that may fail during an update before the failure action is invoked, specified as a floating point number between 0 and 1.
    - `Order` 'stop-first' | 'start-first' — The order of operations when rolling out an updated task. Either the old task is shut down before the new task is started, or the new task is started before the old task is shut down.
  - `RollbackConfig` object — Specification for the rollback strategy of the service.
    - `Parallelism` integer — Maximum number of tasks to be rolled back in one iteration (0 means unlimited parallelism).
    - `Delay` integer — Amount of time between rollback iterations, in nanoseconds.
    - `FailureAction` 'continue' | 'pause' — Action to take if an rolled back task fails to run, or stops running during the rollback.
    - `Monitor` integer — Amount of time to monitor each rolled back task for failures, in nanoseconds.
    - `MaxFailureRatio` number — The fraction of tasks that may fail during a rollback before the failure action is invoked, specified as a floating point number between 0 and 1.
    - `Order` 'stop-first' | 'start-first' — The order of operations when rolling back a task. Either the old task is shut down before the new task is started, or the new task is started before the old task is shut down.
  - `Networks` NetworkAttachmentConfig[] — Specifies which networks the service should attach to.
    - `Target` string — The target network for attachment. Must be a network name or ID.
    - `Aliases` string[] — Discoverable alternate names for the service on this network.
    - `DriverOpts` object — Driver attachment options for the network target.
  - `EndpointSpec` EndpointSpec — Properties that can be configured to access and load balance a service.
    - `Mode` 'vip' | 'dnsrr' — The mode of resolution to use for internal load balancing between tasks.
    - `Ports` EndpointPortConfig[] — List of exposed ports that this service is accessible on from the outside. Ports can only be provided if `vip` resolution mode is used.
      - `Name` string
      - `Protocol` 'tcp' | 'udp' | 'sctp'
      - `TargetPort` integer — The port inside the container.
      - `PublishedPort` integer — The port on the swarm hosts.
      - `PublishMode` 'ingress' | 'host' — The mode in which port is published. <p><br /></p> - "ingress" makes the target port accessible on every node, regardless of whether there is a task for the service running on that node or not. - "host" bypasses the routing mesh and publish the port directly on the swarm node where that service is running.

## Response `200`

no error

- ServiceUpdateResponse
  - `Warnings` string[] — Optional warning messages

## Other responses

- `400` — bad parameter
- `404` — no such service
- `500` — server error
- `503` — node is not part of a swarm

---

[API](https://skmtc.net/aliyun/apis/docker-engine-api.md) · [All operations](https://skmtc.net/aliyun/apis/docker-engine-api/llms.txt) · [OpenAPI document](https://skmtc-service-staging.skmtc.workers.dev/v1/apis/aliyun/docker-engine-api/versions/04bb09da9ccb/schema)
