Turn single host Docker host into a Multi-host Docker Swarm Mode. Becomes Manager By default, Docker works as an isolated single-node. All containers are only deployed onto the engine. Swarm Mode turns it into a multi-host cluster-aware engine.
The first node to initialise the Swarm Mode becomes the manager. As new nodes join the cluster, they can adjust their roles between managers or workers.
Task: Create Swarm Mode Cluster
Swarm Mode is built into the Docker CLI. You can find an overview the possibility commands via
docker swarm --help
The most important one is how to initialise Swarm Mode. Initialisation is done via init.
docker swarm init
Task: Add Worker Node
With Swarm Mode enabled, it is possible to add additional nodes and issues commands across all of them. If nodes happen to disappear, for example, because of a crash, the containers which were running on those hosts will be automatically rescheduled onto other available nodes. The rescheduling ensures you do not lose capacity and provides high-availability.
We first ask the manager what the token is via swarm join-token and join the cluster
token=$(docker -H [[HOST_IP]]:2345 swarm join-token -q worker) && docker swarm join [[HOST_IP]]:2377 --token $token
You can view all nodes in the cluster using
docker node ls