edit-icon download-icon

Number of containers in a service

Last Updated: Feb 12, 2018

Template version

Compose V1/V2 Compose V3
The aliyun.scale label. replicas in Compose. This function is equivalent to the Replicated Service of swarm mode. When a container malfunctions, a new container will be automatically created to make sure that replicas is equal to the specified number.

Compose V1/V2

scale

Set the number of containers for a service to scale horizontally. Docker Compose V1/V2 can only start one container in each service. To expand the number of containers, manually set the number after the container is started.

You can use the Container Service expansion label scale to scale as the container is started.

Moreover, after a container is deleted, you can redeploy the application by completing the following steps:

  1. Log on to the Container Service console.
  2. Click Applications in the left-side navigation pane.
  3. Click Redeploy at the right of the application you want to redeploy. Then, Container Service restarts the container or creates a new container to restore the number of containers to the specified quantity.

Orchestration example:

  1. web:
  2. image: wordpress:4.2
  3. ports:
  4. - 80
  5. links:
  6. - db:mysql
  7. labels:
  8. aliyun.scale: "3"
  9. db:
  10. image: mysql
  11. environment:
  12. - MYSQL_ROOT_PASSWORD=password

Compose V3

replicas

This function is equivalent to the Replicated Service (see replicas) of swarm mode. When a container malfunctions, a new container will be automatically created to make sure that replicas is equal to the specified number.

Orchestration example:

  1. version: '3'
  2. services:
  3. worker:
  4. image: dockersamples/examplevotingapp_worker
  5. networks:
  6. - frontend
  7. - backend
  8. deploy:
  9. mode: replicated
  10. replicas: 6

mode

The mode can be configured as Global (one container on each node) or Replicated (specified number of containers). Replicated is configured by default.

  1. version: '3'
  2. services:
  3. worker:
  4. image: dockersamples/examplevotingapp_worker
  5. deploy:
  6. mode: global
Thank you! We've received your feedback.