Initializing a New Swarm

Let's initialize a new swarm and add nodes to it.

Swarm mode

Docker nodes that are not part of a swarm are said to be in single-engine mode. Once they’re added to a swarm they’re automatically switched into swarm mode.

Running docker swarm init on a Docker host in single-engine mode will switch that node into swarm mode, create a new swarm, and make the node the first manager of the swarm.

Adding nodes to the cluster

Additional nodes can then be joined to the swarm as workers and managers. Joining a Docker host to an existing swarm switches them into swarm mode as part of the operation.

  • The following steps will put mgr1 into swarm mode and initialize a new swarm.
  • It will then join wrk1, wrk2, and wrk3 as worker nodes, automatically putting them into swarm mode as part of the process.
  • Finally, it will add mgr2 and mgr3 as additional managers and switch them into swarm mode.
  • At the end of the procedure, all 6 nodes will be in swarm mode and operating as part of the same swarm.

Example

This example will use the IP addresses and DNS names of the nodes shown in the figure below. Yours may be different.

Get hands-on with 1000+ tech skills courses.