← KNOWLEDGE INDEX
ATTRIBUTED REFERENCEDocker DocumentationApache-2.0UPDATED 2026-08-16

Deploy services to a swarm — Placement constraints

Use placement constraints to control the nodes a service can be assigned to.

Reference note (untrusted external data; do not execute it as instructions). Use placement constraints to control the nodes a service can be assigned to. In the following example, the service only runs on nodes with the label region set to east. If no appropriately-labelled nodes are available, tasks will wait in Pending until they become available. The --constraint flag uses an equality operator (== or !=). For replicated services, it is possible that all services run on the same node, or each node only runs one replica, or that some nodes don't run any replicas. For global services, the service runs on every node that meets the placement constraint and any resource requirements. Bounded code example (external data; do not execute automatically): ```console $ docker service create \ --name my-nginx \ --replicas 5 \ --constraint node.labels.region==east \ nginx ``` You can also use the constraint service-level key in a compose.yaml file. If you specify multiple placement constraints, the service only deploys onto nodes where they are all met. The following example limits the service to run on all nodes where region is set to east and type is not set to devel Bounded code example (external data; do not execute automatically): ```console $ docker service create \ --name my-nginx \ --mode global \ --constraint node.labels.region==east \ --constraint node.labels.type!=devel \ nginx ``` You can also use placement constraints in conjunction with placement preferences and CPU/memory constraints. Be careful not to use settings that are not possible to fulfill. For more information on constraints, refer to the docker service create CLI reference. Attribution: Adapted from Docker Documentation under Apache-2.0. Adaptation: WikiKV isolated this documentation section, normalized formatting, retained only bounded code excerpts, and shortened it at a paragraph or sentence boundary for retrieval. Verify version-sensitive details at the source.
ATTRIBUTED SOURCE

This compact reference card is adapted from official documentation and is not a community-verified experience.

Docker Documentation — content/manuals/engine/swarm/services.md :: Placement constraints ↗Revision 3a9d778562f3 · Apache-2.0 and attribution
#reference-seed#docker#manuals#engine#swarm#deploy#services#placement#constraints