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:
curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh get-docker.shVerify:
docker --versionStep 2: Initialize Swarm Mode
On the primary server (manager node):
docker swarm init --advertise-addr <MANAGER-IP>This will output a join token for worker nodes, like:
docker swarm join --token SWMTKN-1-xyz <MANAGER-IP>:2377Run 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:
docker service create --name webapp --publish 80:80 nginxCheck running services:
docker service lsView replicas (containers):
docker service ps webappVisit your server IP in the browser — you’ll see the Nginx welcome page!
Step 4: Scale Your Application
Increase replicas (containers):
docker service scale webapp=5Docker 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:
docker service update --image nginx:latest webappSwarm gradually replaces old containers while keeping the app online.
Step 6: Persist Data and Manage Volumes
For databases or uploads, attach volumes:
docker service create --name db \
--mount type=volume,source=db_data,target=/var/lib/mysql \
mysql:8Swarm manages volume placement and replication for data consistency.
Step 7: Secure and Manage the Swarm
List nodes:
docker node lsPromote a worker to manager (for redundancy):
docker node promote worker-nodeEncrypt internal communication:
docker swarm update --autolock=trueConclusion
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.

