Based on: https://github.com/docker/labs/blob/master/swarm-mode/beginner-tutorial/README.md https://docs.docker.com/engine/swarm/

Check out the documentation on Docker Swarm Mode for more information.

Since this example would require various machine it can be done online using: https://labs.play-with-docker.com/ you will need a Docker ID at https://hub.docker.com/signup

What is a Docker Swarm?

Docker swarm is a container orchestration tool, meaning that it allows the user to manage multiple containers deployed across multiple host machines.


You can use the Docker CLI to create a swarm, deploy application services to a swarm, and manage swarm behavior. In the same way that you can use Docker Compose to define and run containers, you can define and run Swarm service stacks.

https://i.imgur.com/JI1daE6.png

One of the key benefits associated with the operation of a docker swarm is the high level of availability offered for applications.

About data

Swarm Mode itself does not do anything different with volumes, it runs any volume mount command you provide on the node where the container is running. If your volume mount is local to that node, then your data will be saved locally on that node. There is no built in functionality to move data between nodes automatically.

We will not consider this detail here. If interested, a good starting point is this: https://docs.docker.com/engine/swarm/services/#give-a-service-access-to-volumes-or-bind-mounts or this: https://devopsian.net/posts/share-persistent-storage-volumes-in-swarm/

Creating the nodes and Swarm

We start creating 5 nodes (the maximum allowed) to get something like this (IP addresses will vary):

Untitled

We will now create a swarm by initializing it on the first node (node1). This is done using the command:

[node1] $ docker swarm init --listen-addr <IP_node1> --advertise-addr <IP_node1>