Stop being afraid of Docker Swarm!
Docker Swarm In A Nutshell
This simple tutorial shows how a running docker swarm cluster can be created in ~15 minutes.

I created a follow-up guide to show important services that should be used in every Docker Swarm. The guide is based on this tutorial.
Overview
1. Introduction
|--- 1.1 Why Docker Swarm
|--- 1.2 Prerequisites
2. Create the Docker Swarm
|--- 2.1 Installing dependencies
|--- 2.2 Initialize the Docker Swarm
|--- 2.3 Finalising the Docker Swarm
3. Optional enhancement
|
4. Closing Notes1. Introduction
Whenever you read “Docker Swarm” we are actually talking about “Docker Swarm mode”. (not the deprecated product Docker swarm)
1.1 Why Docker Swarm?
Docker Swarm is the right tool to deploy your application stacks to production, in a distributed cluster, using the same files used by Docker Compose locally.
Additional advantages are:
- Replicability (dev files can be used in production)
- Robustness (fault-tolerant clusters)
- Simplicity and speed for development and deployment
The main benefit of Docker Swarm is simplicity and development speed while still being able to set up a distributed cluster ready for production in 15 minutes.
1.2 Prerequisites
To follow this tutorial on Docker Swarm you need these prerequisites:
- Basic familiarity with Linux and Docker
- Need access to at least 2 (I used four) ubuntu servers from a cloud provider on which the Docker Swarm will run
- A domain that points to one of your servers
2. Create the Docker Swarm
2.1 Installing dependencies
In a freshly installed server infrastructure, every dependency has to be installed to create the swarm cluster. These include Updating the operating system and installing the docker-engine
To update the operating system to an up-to-date version
$> sudo apt-get update && sudo apt-get upgradeSubsequently, curl can be used to download get-docker.sh which is a script created by docker.com to easily install docker on a system:
$> curl -fsSL https://get.docker.com -o get-docker.shThis curl command opens a website, read the content and transfer its content into the file get-docker.sh
Ultimately, the file has to be executed (as a root user):
sh get-docker.shThis script installs everything you need to use docker at your server.
2.2 Initialize the Docker Swarm
After the Docker installation is done choose your Manager node. The Manager node will be the server within your cluster which does all the deployment and managing. The Manager node should be the server within the environment whose IP is targeted by a domain name.
On your manager execute the following command:
docker swarm init --advertise-addr X.X.X.XThis command activates swarm mode on the server. The advertise-addr has to be the internal IP from the server. (normally if you buy more than one server from the same hosting company you can put all of them into an internal network and get the internal IP).
2.3 Finalising the Docker Swarm
The last step is joining the docker swarm from the other servers. After executing the previous command there will be some lines printed in the end that should be executed on the remaining servers in your cluster. It will look like this:
docker swarm join --token SOME_CRYPTIC_HASH_TOKEN X.X.X.X:2377 Execute the command on every other server in your network which will then connect to the Worker node to your Manager.
3. Optional enhancement
Now that the swarm is ready to be used it is possible to deploy services.
I would suggest deploying at least Portainer. Portainer is a container management service that could be used for managing and deploying services.
As a starting point, you can use this docker-compose.yml





