4. Swarm Manager
• Manages the Nodes in the Cluster
• Uses Docker APIs to access the Docker Daemon
running on each node
• Nodes are added to the Swarm manager by
callback from Discovery Service’s fetch() function
• Elements of a Swarm Cluster Manager
– Event Handler
– Map of Nodes
– Store
– Options
5. Swarm Node
• Runtime Instance representing a node in the Cluster.
• Talks to the actual Host using Docker Go Client
• Created from a DiscoveryEntry fetched from a Discovery Service
• Elements of Swarm Node
– Id
– IP Address (of remote host)
– Map of Containers
– Map of Images
– Health state of the node
– Total CPUs
– Used CPUs
– Total Memory
– Used Memory
6. Scheduler
• Responsible for scheduling a container on a
Node
• Pluggable architecture – Bring your own
scheduler
• Elements of a Scheduler
– Placement Strategy Instance
– Array of Filters
7. Scheduler .. contd
• The `Docker Swarm` scheduler comes with multiple strategies.
• These strategies are used to rank nodes using a scores
computed by the strategy. `Docker Swarm` currently supports
2 strategies:
– BinPacking Strategy
– Random Strategy
Usage : You can choose the strategy you want to use with the `--
strategy` flag of `swarm manage`
8. Scheduler .. contd
BinPacking strategy
• The BinPacking strategy will rank the nodes using their CPU and RAM
available and will return the node the most packed already.
• This avoid fragmentation, it will leave room for bigger containers on
unused machines.
Random strategy
• The Random strategy, as it's name says, chooses a random node, it's used
mainly for debug
9. Scheduler Filters
• Scheduler uses the following filters for container
placement on a node
– Affinity Filter
– Constraint Filter : When creating a container, the user
can select a subset of nodes that should be
considered for scheduling by specifying one or more
sets of matching key/value pairs.
– Port Filter : Select node where public port required by
the container is not already used
– Health Filter : Select only healthy nodes from the
cluster
10. Swarm Store
• Stores the state of the Cluster.
• Currently implemented as a JSON file
• State is loaded in memory when the cluster starts
• Lifecycle events of the store
– Get state for a key
– Store the state of a container
– Load all the data stored
– Replace the state of the key with a new state
– Delete the state
11. Discovery Service
• Helps Swarm Manager discover nodes
• Three main functions
– Register : Registers a new node
– Watch : Callback method for Swarm Manager
when a new Node is added to the Discovery
Service
– Fetch : Fetch the List of Entries
12. Discovery Services
• Token Based
• etcd based
• Zookeeper based
• File Based
• Consul Based
• Bring your own?
14. Token Based Discovery Service
• Based on REST End Point hosted on Docker-
hub
• URL Queried for entries is
DISCOVERY_URL = "https://discovery-stage.hub.docker.com/v1"
HTTP GET https://discovery-stage.hub.docker.com/v1/clusters/<token-id>
16. Swarm CLI
• Allows Setting up and Managing the Cluster
create a cluster
$ docker run --rm swarm create
6856663cdefdec325839a4b7e1de38e8
On each nodes, start the swarm agent
$ docker run -d swarm join --addr=<node_ip:2375> token://<cluster_id>
17. Swarm CLI
Start the manager on any machine / Laptop to manage the
cluster
$ docker run -d -p <swarm_port>:2375 swarm manage token://<cluster_id>
Use the regular docker cli
$ docker -H tcp://<swarm_ip:swarm_port> info
$ docker -H tcp://<swarm_ip:swarm_port> run ...
$ docker -H tcp://<swarm_ip:swarm_port> ps
$ docker -H tcp://<swarm_ip:swarm_port> logs ...
…
List nodes in your cluster
$ docker run --rm swarm list token://<cluster_id>
<node_ip:2375>
18. Swarm APIs
• Compatible with Docker Remote API with
some differences
• Containers
GET /containers/(id)
POST /containers/create
DELETE /containers/(id)
POST /container/(id)/start
additional parameters passed in the POST body
20. Summary
• Docker Swarm allows you to use native Docker
CLI commands and APIs to manage containers
across a cluster of nodes
• It has a basic scheduler which can be
enhanced
• Pluggable Discovery mechanism