Set the deployment constraints for a service.
Container Service supports the container deployment constraints compatible with Docker Swarm. You can control the deployment of a container with the Docker Swarm filters. But the community version of Docker Compose does not have relevant capabilities to control the direct deployment constraint for a service.
In Container Service, you can add
environment to constrain the affinity between services so as to control the service deployment policy. Container Service supports soft affinity and hard affinity between services.
In this example,
affinity:service!=db is the deployment constraint for the
web service. In this way, the
web service is always deployed to nodes where the
db service is not deployed. Therefore, when a node is invalid, the service availability is enhanced. When your cluster has only one node, as hard anti-affinity is specified, the deployment will fail because it cannot meet the specified mandatory constraints.