Create your First Swarm

In this section, you will create swarm by using Play-with-Docker. We are going to create a swarm with three nodes.

1. Add instances
Click Add new instance on the left side three times to create three nodes.
2. Initialize the swarm on node (let say node 1,then it will act as manager):
          $ docker swarm init --advertise-addr eth0
 docker swarm init  - use to initialize swarm,
--advertise-addr    
- the address in which the other nodes will use to join the swarm. 
3. Add a worker(node) to this swarm
This docker swarm init command generates a join token. The token ensures that only authentic nodes can join the swarm. We need to use this token to join the other nodes to the swarm. The output includes the full command docker swarm join, which you can just copy/paste to the other nodes.
It looks something like this –[copy entire text and paste on other nodes(instances)]
docker swarm join --token SWMTKN-1-2tauvds6jx6d21lb07xz6ht98sm4rum8jrh1wmuoe8pqow9hga-9j1wb49j7wfu3al5deccjm138 192.168.0.23:2377
4. Verify your three-node cluster [on node1(manager node), run the following command ]
              $ docker node ls
[command will only execute on the node1(manager) terminal and will not execute on workers(node 2 and 3) terminal]
Managers node -manage the state of the swarm.
Workers  node - used to run containers at scale. (by default, managers used to run containers)