Swarm mode lets you create acluster of one or more Docker Engines called a swarm. A swarm consistsof one or more nodes: physical or virtual machines running DockerEngine.
There are two types of nodes:managers andworkers.
If you haven't already, read through theSwarm mode overview andkey concepts.
Manager nodes handle cluster management tasks:
- Maintaining cluster state
- Scheduling services
- Serving Swarm mode HTTP API endpoints
Using aRaft implementation, the managersmaintain a consistent internal state of the entire swarm and all the servicesrunning on it. For testing purposes it is OK to run a swarm with a singlemanager. If the manager in a single-manager swarm fails, your servicescontinue to run, but you need to create a new cluster to recover.
To take advantage of Swarm mode's fault-tolerance features, we recommendyou implement an odd number of nodes according to your organization'shigh-availability requirements. When you have multiple managers you can recoverfrom the failure of a manager node without downtime.
A three-manager swarm tolerates a maximum loss of one manager.
A five-manager swarm tolerates a maximum simultaneous loss of twomanager nodes.
An odd number
N
of manager nodes in the cluster tolerates the loss of at most(N-1)/2
managers.Docker recommends a maximum of seven manager nodes for a swarm.Important
Adding more managers does NOT mean increasedscalability or higher performance. In general, the opposite is true.
Worker nodes
Worker nodes are also instances of Docker Engine whose sole purpose is toexecute containers. Worker nodes don't participate in the Raft distributedstate, make scheduling decisions, or serve the swarm mode HTTP API.
You can create a swarm of one manager node, but you cannot have a worker nodewithout at least one manager node. By default, all managers are also workers.In a single manager node cluster, you can run commands like docker service create
and the scheduler places all tasks on the local engine.
To prevent the scheduler from placing tasks on a manager node in a multi-nodeswarm, set the availability for the manager node to Drain
. The schedulergracefully stops tasks on nodes in Drain
mode and schedules the tasks on anActive
node. The scheduler does not assign new tasks to nodes with Drain
availability.
Refer to thedocker node update
command line reference to see how to change node availability.
You can promote a worker node to be a manager by running docker node promote
.For example, you may want to promote a worker node when youtake a manager node offline for maintenance. Seenode promote.
You can also demote a manager node to a worker node. Seenode demote.