Docker Swarm
Author : Rajdeep Dua, VMware
Twitter : @rajdeepdua
Last Updated : March 25 2015
Overview
• Allows to manage Docker Cluster Remotely
• Key Components
– Swarm Manager
– Swarm Node
– Scheduler
– Discovery
Architecture Diagram
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
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
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
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`
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
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
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
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
Discovery Services
• Token Based
• etcd based
• Zookeeper based
• File Based
• Consul Based
• Bring your own?
Docker Swarm Architecture - Exploded
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>
Discovery Fetch Entries
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>
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>
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
Swarm APIs…
Images
GET /images/json
POST /images/create
DELETE /images/(id)
GET /images/search
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

Docker Swarm Introduction

  • 1.
    Docker Swarm Author :Rajdeep Dua, VMware Twitter : @rajdeepdua Last Updated : March 25 2015
  • 2.
    Overview • Allows tomanage Docker Cluster Remotely • Key Components – Swarm Manager – Swarm Node – Scheduler – Discovery
  • 3.
  • 4.
    Swarm Manager • Managesthe 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 • RuntimeInstance 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 forscheduling 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 BinPackingstrategy • 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 • Scheduleruses 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 • Storesthe 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 • HelpsSwarm 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 • TokenBased • etcd based • Zookeeper based • File Based • Consul Based • Bring your own?
  • 13.
  • 14.
    Token Based DiscoveryService • 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>
  • 15.
  • 16.
    Swarm CLI • AllowsSetting 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 themanager 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 • Compatiblewith 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
  • 19.
    Swarm APIs… Images GET /images/json POST/images/create DELETE /images/(id) GET /images/search
  • 20.
    Summary • Docker Swarmallows 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