avatarPaul Knulst

Summary

The web content provides a comprehensive guide on setting up a Docker Swarm cluster, detailing the steps to create a robust, fault-tolerant, and scalable production environment using Docker Swarm mode, with a focus on simplicity and rapid deployment.

Abstract

The article titled "Stop being afraid of Docker Swarm!" offers a concise tutorial aimed at demystifying the process of creating a Docker Swarm cluster. It emphasizes the advantages of Docker Swarm for deploying applications to a distributed cluster using the same configuration files as Docker Compose. The guide highlights the ease of setting up a production-ready cluster within approximately 15 minutes, the replicability of development files for production use, and the robustness of the system. It outlines prerequisites such as basic Linux and Docker knowledge, access to multiple Ubuntu servers, and a domain name. The tutorial covers the installation of dependencies, initialization of the Docker Swarm, and finalizing the cluster setup. Additionally, it suggests deploying Portainer for container management and mentions the use of Traefik for SSL setup. The author, Paul Knulst, concludes by inviting feedback and announcing a follow-up article on essential services for a Docker Swarm.

Opinions

  • The author believes that Docker Swarm is an ideal tool for deploying applications to production due to its simplicity, speed, and ability to use the same configuration files from development to production.
  • Docker Swarm's robustness and fault tolerance are seen as key benefits for setting up a distributed cluster.
  • The use of Portainer is highly recommended by the author for managing and deploying services within the Docker Swarm.
  • The author values the community's input and encourages readers to share their thoughts and ideas on the topic.
  • A forthcoming guide by the author will focus on important services to enhance a Docker Swarm setup, indicating a commitment to providing ongoing, practical insights for Docker Swarm users.

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.

Photo by Ian Taylor on Unsplash

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 Notes

1. 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 upgrade

Subsequently, 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.sh

This 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.sh

This 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.X

This 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

After saving this file on the Manager node it can be deployed within the Docker Swarm:

$> docker stack deploy -c docker-compose.portainer.yml portainer

Immediately after executing the command, Portainer can be accessed at http://YOUR_DOMAIN:9000

4. Closing Notes

Keep in mind that the example Portainer instance will be deployed without SSL. To achieve this you can use a load balancer like traefik. As a starting point, you can read an article that explains how to set up a traefik service within a plain docker environment:

Additionally, I am working on a follow-up article that contains information about the best services you want to have in a Docker Swarm. traefik will be part of it as the load balancer. Follow or Subscribe to me to get informed when my “docker swarm services” article is published on Medium.

That’s the end of this blog. I would love to hear your ideas and thoughts 🤗 Please jot them down below 👇👇👇

✍️ Written by

Paul Knulst

👨🏻‍💻🤓🏋️‍🏸🎾🚀

Husband, father of two, geek, lifelong learner, tech lover & software engineer

This article was initially published on my blog at https://www.paulsblog.dev/docker-swarm-in-a-nutshell/

Say Hello 🙌 on:

Twitter, LinkedIn, GitHub, Personal site

Docker
DevOps
Software Engineering
Tech
How To
Recommended from ReadMedium