CraftedTemplate
Blog How to Use Docker Swarm for Scalable Hosting (Step-by-Step Tutorial)

How to Use Docker Swarm for Scalable Hosting (Step-by-Step Tutorial)

11/2/2025 • Festus Ayomike
How to Use Docker Swarm for Scalable Hosting (Step-by-Step Tutorial)

Once your website or web app grows beyond a single container, you’ll need a system that can manage multiple instances, balance traffic, and recover from failures automatically. That’s where Docker Swarm comes in.

In this guide, you’ll learn how to create, deploy, and scale a website using Docker Swarm — Docker’s built-in container orchestration tool.

See Also: How to Monitor Website Uptime and Performance (Step-by-Step Tutorial)

What Is Docker Swarm?

Docker Swarm turns multiple Docker hosts (servers) into a single virtual cluster.

You can:

  • Deploy services across multiple servers
  • Scale apps up or down with one command
  • Enable built-in load balancing
  • Maintain zero-downtime updates

It’s simpler than Kubernetes and perfect for small-to-medium production setups.

Step 1: Install Docker on All Servers

On each VPS or cloud instance:

Code · batchfile
curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh get-docker.sh

Verify:

Code · batchfile
docker --version

Step 2: Initialize Swarm Mode

On the primary server (manager node):

Code · batchfile
docker swarm init --advertise-addr <MANAGER-IP>

This will output a join token for worker nodes, like:

Code · batchfile
docker swarm join --token SWMTKN-1-xyz <MANAGER-IP>:2377

Run that command on all worker nodes to join the swarm.

See Also: How to Set Up Automatic Backups for Websites and Databases (Complete Guide)

Step 3: Deploy Your First Service

Deploy a simple web app:

Code · batchfile
docker service create --name webapp --publish 80:80 nginx

Check running services:

Code · batchfile
docker service ls

View replicas (containers):

Code · batchfile
docker service ps webapp

Visit your server IP in the browser — you’ll see the Nginx welcome page!

Step 4: Scale Your Application

Increase replicas (containers):

Code · batchfile
docker service scale webapp=5

Docker automatically spreads these containers across available nodes, balancing load efficiently.

See Also: How to Optimize Website Speed and Server Performance (Full Guide)

Step 5: Update Your Application

Deploy new versions with zero downtime:

Code · batchfile
docker service update --image nginx:latest webapp

Swarm gradually replaces old containers while keeping the app online.

Step 6: Persist Data and Manage Volumes

For databases or uploads, attach volumes:

Code · sh
docker service create --name db \
  --mount type=volume,source=db_data,target=/var/lib/mysql \
  mysql:8

Swarm manages volume placement and replication for data consistency.

Step 7: Secure and Manage the Swarm

List nodes:

Code · batchfile
docker node ls

Promote a worker to manager (for redundancy):

Code · batchfile
docker node promote worker-node

Encrypt internal communication:

Code · sh
docker swarm update --autolock=true

Conclusion

Docker Swarm bridges the gap between simple container setups and full-scale orchestration.

With minimal configuration, you can scale your applications, balance traffic, and maintain uptime — all using native Docker commands.

In the next Hosting Academy post, we’ll explore Infrastructure as Code with Terraform — bringing automation to the next level.