Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

364
Views
Docker placement preference vs Docker placement constraints

I am learning Docker. As part of my learning there is one topic I haven't understood. The usage of the Docker placement preferences when compared with constraints in Docker.

I have been keep searching in internet and asked many people everyone aware of the constraints not the preferences. I haven't found any good reference in internet. What is the use of placement preferences in Docker? When should I use them? Any sample example?

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

Placement prefs allow you to "spread" your replicas across nodes with certain tags, choosing to put the replicas as much "diverse" as possible.

Constraints will constrain (limit) the replicas to those nodes that match the constraint.

Image you have 4 servers in 2 datacenters (east, west) and some of the servers have an SSD drive, while others don't.

If you apply the following labels to the nodes:

node-1: datacenter=us-east, disk=ssd
node-2: datacenter=us-east, disk=ssd
node-3: datacenter=us-west, disk=sas
node-4: datacenter=us-west, disk=nl-sas

If you would deploy a service with 2 replicas and you want to provide geographic redundancy, you would start that service as follows:

docker service create \
  --replicas 2 \
  --name webserver \
  --placement-pref 'spread=node.labels.datacenter' \
  mywebservice:production

Docker Swarm would then try to "spread" the 2 replicas across both datacenters, so you'll end up with 1 replica on either node-1 or node-2, and the other replica on node-3 or node-4.

If you have a service (eg a reporting job) that does a lot of IOPS, you'll probably want to use your SSD equiped servers, so you'll place a constraint on the service:

docker service create \
  --constraint 'node.labels.disk == ssd' \
  myreporter:latest
over 4 years ago · Santiago Trujillo Report

0

Refer to "Control service placement" section in https://docs.docker.com/engine/swarm/services/

In short Placement constraint limits where a task can run (a task will not run on a node unless it satisfies the constraint, it will remain in pending state)

While placement constraints limit the nodes a service can run on, placement preferences try to place tasks on appropriate nodes in an algorithmic way (currently, only spread evenly). Placement preference helps you in distributing the tasks based on a constraint across the nodes.

e.g. placement constraint of node.region=east will let a task only run on nodes labelled "east" whereas, placement preference of node.region=east will help you spread the tasks across nodes evenly based node.region. If any node does not have this label, it will still get the task.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!