Docker Swarm is a container orchestration tool that allows you to manage and scale a cluster of Docker hosts. While standalone Docker is great for running containers on a single host, Docker Swarm extends this capability to a group of machines, forming a swarm that can efficiently distribute and manage containerised applications.

In this article:

If you are looking for other deployment tutorials checkout out one of these:

Docker Swarm

If you used a regular Docker deployments, you already know the flexibility containerisation provides.

Docker Swarm is a next step in scaling your applications outside of capacity of a single server.

Docker Swarm allows you:

  • Scale your application(s) horizontally – run many copies of your application;
  • Scale your server resources by adding, removing or replacing servers with changing requirements and workload;
  • Have servers across multiple cloud providers or regions, avoiding vendor lock;
  • Add more apps to cluster without the need to worry and handle placement of containers across your servers
  • Cut down costs by running on cloud providers that offer the best price for servers

Scaling applications in Docker Swarm Cluster

You can easily manage a number of containers/replicas that will be running for each process in your app.

You can scale every process of every app individually at any given time.

Compared to a standalone Docker instance, Docker Swarm allows scaling a process even in a cluster with only one server, fully utilising its resources.

How Docker Swarm Cluster works?

Docker Swarm works by turning a group of Docker hosts into a single virtual host, allowing you to manage and orchestrate containers across multiple machines.

Appliku initializes Docker Swarm on the first server in your cluster, making it a Swarm Manager.

Other machines that you add to swarm will join as worker nodes.

An Nginx server will be deployed on the first server to load balance the traffic between all containers across all worker nodes that are responding to HTTP requests.

Docker Swarm overlay network takes care of distributing the traffic and removing broken nodes from load balancing.

If a worker node fails or is disconnected, the Swarm Manager reschedules the tasks on other healthy nodes, maintaining the desired state of the services.

Every application you deploy to Managed Docker Swarm Cluster is a separate stack.

Each process in your application becomes a service in the stack.

How to install docker swarm on Ubuntu

In order to create a Managed Docker Swarm Cluster you need to provide a fresh Ubuntu 22.04 LTS or 24.04 LTS or Debian 12 server with x86 or arm64 architecture. They should all be same architecture though.

Appliku will install all necessary packages and configure them, including Docker.

Then docker swarm will be initialized.

If you add a server into an existing cluster then instead of initializing Docker Swarm, the server will be joined to an existing cluster.

Where are Docker Swarm logs

You can access logs of every application in the dashboard by going from Application Overview page to App Logs and selecting what process/service you want to fetch logs for.

Multi-Cloud Support in Managed Docker Swarm

You can add servers from different providers to a given cluster, this allows you to optimise costs, put servers closers to your customers and increase stability and availability of your deployed app.

How to create and prepare a Docker Swarm cluster to deploy your app

Requirements: - A server for a leader node, which will manage the cluster and will run nginx load balancer, - A server for a worker node, which will run your applications, - A build servers. It is recommended to have your build servers not be part of the cluster(Standalone server) as depending on your application build requirements it can affect operations of the chosen node. It is highly not recommended choose cluster leader as the build server. Optional requirement: - Database server, outside of the cluster. Databases deployed via Appliku can only be deployed to standalone servers

1. Create a leader server

Go to servers and click Add a Server as usual, but at instead of creating a standalone server, pick Create a new Cluster and give it a name, then click Create a server

2. Wait for leader to finish setup process

After creating a server as a new cluster leader you will be taken to a new cluster page. Wait for the leader to finish setting up.

3. Add a container registry(CR) credentials

To deploy an application in a cluster you have to add a container registry credentials where the application image will be pushed to after then build and pulled by cluster nodes to deploy.

While you can use any Container Registry(CR) to deploy your apps in Docker Swarm, the easiest option is to use CR from GitHub or GitLab, where your git repository is hosted.

When you add credentials they will be verified by and added to the leader node and distributed across all nodes upon deployment.

Also, they will be stored to push images from the build servers after successful builds.

4. Add a build server(s)

For a cluster, in order to build an application it needs to have a build server or multiple. Multiple build servers are good if you have a lot of concurrent builds if you deploy often and build takes a lot of time.

Add a server as usual to Appliku. When the setup process has finished, go to your cluster and scroll down to the Build Servers and click add Build server. Select the server you prepared for this role and add it.

Add more build server if you need them.

5. Create an application in cluster

Create an application, as a deployment target select your newly created cluster. Add a database if you wish to use one deployed via Appliku. You can deploy a database only on a standalone server, not in a cluster. It is possible to use a server you selected as a build server for running a database, although not recommended, as build process(es) may affect the database stability. Add processes and environment variables, choose build settings and hit deploy the app.

The build process is the same as for regular apps, but it includes the push and pull from the repo.

On the processes tab in Application settings you can choose the scale for each process. Scale sets the number of replicas of the process in Docker Swarm terms.

6. Limitations compared to standalone apps

  • One-off jobs, like release phase commands, and commands you run from the dashboard "Run Command" will be executed from the leader node,
  • Persistent Volumes are not supported for apps in clusters