All Products
Document Center

Specified node scheduling

Last Updated: Feb 12, 2018

Swarm mode clusters support setting node constraints by configuring interface parameters or editing your orchestration template in the Container Service console.

Note: The deployment constraint only works for newly created containers. It does not work when existing containers change the configurations.

Set by configuring interface parameters

You can set the constraints when creating an application by using an image.


Set by editing an orchestration template

Template version

Compose V1/V2 Compose V3
The constraint keyword. See placement in Compose. This is a native function of swarm mode and can configure the deployment constraint.

Compose V1/V2

To deploy a service to a specified node, you can use the constraint keyword.

In the following example, the service is deployed to node1.

  1. web:
  2. image: 'nginx:latest'
  3. restart: always
  4. environment:
  5. - constraint:aliyun.node_index==1
  6. ports:
  7. - 80
  8. labels:
  9. aliyun.scale: 2

Compose V1/V2 supports the following expressions:

constraint:aliyun.node_index==1Deploy the service to node1.
constraint:aliyun.node_index!=1 Do not deploy the service to node1.
constraint:aliyun.node_index==(1|2|3)Deploy the service to node1, node2, or node3.
constraint:aliyun.node_index!=(1|2|3)Deploy the service to a machine other than node1, node2, and node3.
affinity:image==~redisTry to deploy the service to a machine with a Redis image.
affinity:service!=~redisTry not to deploy the service to a machine with a Redis service.

Compose V3

In Compose V3, you can also use the constraint keyword to deploy a service to a specified node. However, the syntax of Compose V3 is different from that of Compose V1/V2, and Compose V3 supports multiple deployment constraints.

In the following example, the service is deployed to the manager node.

  1. version: '3'
  2. services:
  3. web:
  4. image: wordpress:4
  5. ports:
  6. - 80
  7. depends_on:
  8. - mysql
  9. deploy:
  10. replicas: 3
  11. restart_policy:
  12. condition: on-failure
  13. placement: #Note
  14. constraints:
  15. - node.role == manager
  16. labels:
  17. aliyun.routing.port_80: wordpress
  18. mysql:
  19. image: mysql:5.7
  20. environment:
  21. - MYSQL_ROOT_PASSWORD=password
  22. deploy:
  23. restart_policy:
  24. condition: on-failure

Compose V3 supports the following syntaxes:

Node attribute Description Example The node ID. == 2ivku8v2gvtg4
node.hostname The node hostname. node.hostname != node-2
node.role The node role, which can be manager or worker. node.role == manager
node.labels Your custom node user tag. == high
engine.labels The Docker Engine label. engine.labels.operatingsystem == ubuntu 14.04