Initializing a New Swarm

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

The process of building a swarm is called initializing a swarm, and this is a high-level process:

  1. Initialize the first manager

  2. Join additional managers

  3. Join workers.

Swarm mode

Before a Docker node joins a swarm, it runs in single-engine mode and can only run regular containers. After joining a swarm, it switches into swarm mode and can run advanced containers called swarm services. More on services later.

When you run a docker swarm init command on a Docker node that’s currently in single-engine mode, Docker switches it into swarm mode, creates a new swarm, and makes the node the first manager of the swarm. You can then add more nodes as managers and workers, and these nodes also get switched into swarm mode.

Adding nodes to the cluster

You’re about to complete all of the following:

  1. Initialize a new swarm from mgr1

  2. Join wrk1 and wrk2 as worker nodes

  3. Join mgr2 and mgr3 as additional managers

After completing the procedure, all five nodes will be in swarm mode and part of the same swarm.

Example

These examples will use the names and IPs of the nodes shown in the figure below. Yours will be different, and you should use your own.

Get hands-on with 1300+ tech skills courses.