Skip to the content.

Compose Deploy Specification

Note:

Deploy is an optional part of the Compose Specification

The Compose Deploy Specification lets you declare additional metadata on services so Compose gets relevant data to allocate adequate resources on the platform and configure them to match your needs.

Attributes

endpoint_mode

endpoint_mode specifies a service discovery method for external clients connecting to a service. Default and available values are platform specific but the Compose Deploy Specification defines two canonical values:

services:
  frontend:
    image: example/webapp
    ports:
      - "8080:80"
    deploy:
      mode: replicated
      replicas: 2
      endpoint_mode: vip

labels

labels specifies metadata for the service. These labels are only set on the service and not on any containers for the service. This assumes the platform has some native concept of “service” that can match the Compose application model.

services:
  frontend:
    image: example/webapp
    deploy:
      labels:
        com.example.description: "This label will appear on the web service"

mode

mode defines the replication model used to run the service on the platform. Either global, exactly one container per physical node, or replicated, a specified number of containers. The default is replicated.

services:
  frontend:
    image: example/webapp
    deploy:
      mode: global

placement

placement specifies constraints and preferences for the platform to select a physical node to run service containers.

constraints

constraints defines a required property the platform’s node must fulfill to run the service container. See example usage here

deploy:
  placement:
    constraints:
      - disktype=ssd

preferences

preferences defines a strategy (currently spread is the only supported strategy) to spread tasks evenly over the values of the datacenter node label. See example usage [here]https://docs.docker.com/reference/cli/docker/service/create/#placement-pref)

deploy:
  placement:
    preferences:
      - spread: node.labels.zone

replicas

If the service is replicated (which is the default), replicas specifies the number of containers that should be running at any given time.

services:
  frontend:
    image: example/webapp
    deploy:
      mode: replicated
      replicas: 6

resources

resources configures physical resource constraints for container to run on platform. Those constraints can be configured as:

services:
  frontend:
    image: example/webapp
    deploy:
      resources:
        limits:
          cpus: '0.50'
          memory: 50M
          pids: 1
        reservations:
          cpus: '0.25'
          memory: 20M

cpus

cpus configures a limit or reservation for how much of the available CPU resources, as number of cores, a container can use.

memory

memory configures a limit or reservation on the amount of memory a container can allocate, set as a string expressing a byte value.

pids

pids tunes a container’s PIDs limit, set as an integer.

devices

devices configures reservations of the devices a container can use. It contains a list of reservations, each set as an object with the following parameters: capabilities, driver, count, device_ids and options.

Devices are reserved using a list of capabilities, making capabilities the only required field. A device must satisfy all the requested capabilities for a successful reservation.

capabilities

capabilities are set as a list of strings, expressing both generic and driver specific capabilities. The following generic capabilities are recognized today:

To avoid name clashes, driver specific capabilities must be prefixed with the driver name. For example, reserving an nVidia CUDA-enabled accelerator might look like this:

deploy:
  resources:
    reservations:
      devices:
        - capabilities: ["nvidia-compute"]
driver

A different driver for the reserved device(s) can be requested using driver field. The value is specified as a string.

deploy:
  resources:
    reservations:
      devices:
        - capabilities: ["nvidia-compute"]
          driver: nvidia
count

If count is set to all or not specified, Compose reserves all devices that satisfy the requested capabilities. Otherwise, Compose reserves at least the number of devices specified. The value is specified as an integer.

deploy:
  resources:
    reservations:
      devices:
        - capabilities: ["tpu"]
          count: 2

count and device_ids fields are exclusive. Compose returns an error if both are specified.

device_ids

If device_ids is set, Compose reserves devices with the specified IDs provided they satisfy the requested capabilities. The value is specified as a list of strings.

deploy:
  resources:
    reservations:
      devices:
        - capabilities: ["gpu"]
          device_ids: ["GPU-f123d1c9-26bb-df9b-1c23-4a731f61d8c7"]

count and device_ids fields are exclusive. Compose returns an error if both are specified.

options

Driver specific options can be set with options as key-value pairs.

deploy:
  resources:
    reservations:
      devices:
        - capabilities: ["gpu"]
          driver: gpuvendor
          options:
            virtualization: false

restart_policy

restart_policy configures if and how to restart containers when they exit. If restart_policy is not set, Compose considers the restart field set by the service configuration.

deploy:
  restart_policy:
    condition: on-failure
    delay: 5s
    max_attempts: 3
    window: 120s

rollback_config

rollback_config configures how the service should be rollbacked in case of a failing update.

update_config

update_config configures how the service should be updated. Useful for configuring rolling updates.

deploy:
  update_config:
    parallelism: 2
    delay: 10s
    order: stop-first