This content originally appeared on DEV Community and was authored by SOVANNARO
Hey there, fellow dev! 👋
Have you ever dreamed of running a real-world web app that can scale across multiple servers, with different services working together like a perfect orchestra? Well, today is your lucky day!
In this post, we’ll show you how to build a multi-service, multi-node web app using Docker Swarm. You’ll learn how to:
✅ Set up multiple nodes (servers)
✅ Create multiple services (like web and database)
✅ Let them talk to each other
✅ Scale like a pro!
Ready? Let’s dive in!
💡 What You'll Build
We’ll create a mini web app with two main services:
- Frontend (web): A simple Nginx server serving a website
- Backend (database): A Redis server (our example backend)
These services will run across multiple nodes in a Docker Swarm cluster — meaning they can survive crashes, scale easily, and balance traffic smartly!
🧱 Step 1: Create a Swarm Cluster
First, you need at least 3 machines (real or virtual). You can use:
- 3 VMs (VirtualBox, EC2, DigitalOcean, etc.)
- Or 3 Docker containers with Swarm support
Example:
Let’s say we have:
manager-node
worker-node-1
worker-node-2
On the manager node:
docker swarm init --advertise-addr <MANAGER-IP>
Copy the join command Docker gives you.
On worker nodes:
docker swarm join --token <TOKEN> <MANAGER-IP>:2377
🎉 Boom! You’ve got a 3-node Swarm cluster!
🛠️ Step 2: Create a Docker Compose File
Now, let’s define our multi-service app.
Create a file called docker-compose.yml
:
version: "3.9"
services:
web:
image: nginx
ports:
- "8080:80"
deploy:
replicas: 3
placement:
constraints: [node.role == worker]
redis:
image: redis
deploy:
replicas: 1
placement:
constraints: [node.role == worker]
What this does:
- Spins up 3 Nginx web servers
- Runs 1 Redis server
- Deploys them only on worker nodes
🚀 Step 3: Deploy the Stack
Copy the docker-compose.yml
to your manager node.
Then deploy it using:
docker stack deploy -c docker-compose.yml myapp
Docker Swarm will magically:
- Schedule your containers across available nodes
- Connect them with an overlay network
- Handle load balancing and failure recovery
You can check the status with:
docker stack services myapp
Or see where containers are running:
docker service ps myapp_web
🔄 Step 4: Scale Like a Boss
Want to handle more traffic?
Just scale your services!
docker service scale myapp_web=5
Boom 💥 — now you have 5 web servers working together, across multiple machines!
🧪 Bonus: Test It!
Visit your server’s IP at port 8080:
http://<ANY_NODE_IP>:8080
You should see the Nginx welcome page. Docker Swarm will balance traffic to all replicas for you.
🧼 Clean Up
To remove the stack:
docker stack rm myapp
🎁 Final Thoughts
You just built a multi-service, multi-node web app like a pro! 🧑💻💪
With Docker Swarm, it’s easy to:
- Create scalable apps
- Run across multiple servers
- Keep everything connected and balanced
Whether you're building a blog, an e-commerce app, or a microservice monster — this is your foundation.
❤️ Enjoyed this?
If this helped you, share it with your dev friends and don’t forget to explore more Docker magic!
This content originally appeared on DEV Community and was authored by SOVANNARO

SOVANNARO | Sciencx (2025-06-26T16:10:25+00:00) 🚀 Create a Multi-Service Multi-Node Web App with Docker Swarm. Retrieved from https://www.scien.cx/2025/06/26/%f0%9f%9a%80-create-a-multi-service-multi-node-web-app-with-docker-swarm/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.