Controlling Container Placement

  • By default a Swarm Service spreads its tasks out over Nodes
    • Tries to also use the least-used node for a task
  • Swarm has multiple ways to control which node a container runs on
  • Can be used together for complex requirements
    • #1 Node Labels plus Service Constraints (<key>=<value>)
      • Hard requirement. Only schedules tasks if Swarm matches constraint
      • Add labels to nodes first, based on location, hardware, or purpose
      • Then use constraints when creating services
    • #2 Service Modes (replicated|global)
      • Global is good for monitoring/logging/proxy/security tools
      • Only set at service create time
    • #3 (new in 17.04+) Placement Preferences (spread)
      • Soft requirement. For now only used to spread across availability zones
    • #4 Node Availability (active|pause|drain)
    • #5 Resource Requirements (cpu|memory)

Requirements for the sub-section examples

  • Created a 3-node (or more) Swarm
  • Not all nodes are managers (1 manager and 2 workers is good)
  • Created the swarm Visualizer service
    • docker run -it -d -p 5000:8080 -v /var/run/docker.sock:/var/run/docker.sock dockersamples/visualizer
  • Visualizer looks like this:

Here manager2 was originally manager but I demoted it to worker for examples purposes.

results matching ""

    No results matching ""