This content originally appeared on DEV Community and was authored by Yash Sonawane
Welcome back! Now that you’ve mastered Docker Compose and Swarm individually, it’s time to combine their powers. In this episode, we’ll explore how to deploy multi-container applications across multiple hosts using Compose with Swarm.
🔹 Why Integrate Compose with Swarm?
- Compose simplifies service definitions.
- Swarm provides orchestration, scaling, and high availability.
- Together, they allow easy deployment of complex applications across clusters.
🔹 Preparing Compose for Swarm
- Docker Compose v3 supports Swarm mode.
- Define services, networks, and volumes as usual.
- Use the
deploysection for Swarm-specific settings:
version: '3.8'
services:
web:
image: nginx:latest
ports:
- "80:80"
deploy:
replicas: 3
update_config:
parallelism: 1
delay: 10s
restart_policy:
condition: on-failure
🔹 Deploying Compose to Swarm
docker stack deploy -c docker-compose.yml mystack
-
docker stack deployinterprets Compose files in Swarm mode. - Services defined in Compose are now Swarm services.
Check running services:
docker stack services mystack
🔹 Scaling & Updates
- Scale a service:
docker service scale mystack_web=5
- Perform rolling updates by updating the image in
docker-compose.ymland redeploying:
docker stack deploy -c docker-compose.yml mystack
🔹 Networking & Secrets
- Overlay networks defined in Compose are created automatically across Swarm nodes.
- Secrets and configs can also be defined in Compose:
secrets:
db_password:
file: ./db_password.txt
services:
db:
image: postgres:latest
secrets:
- db_password
🔹 Best Practices
- Use Compose v3+ for Swarm compatibility.
- Define replicas, update_config, and restart_policy under deploy.
- Use overlay networks for multi-host communication.
- Manage secrets and configs via Compose.
- Test on a small Swarm cluster before production deployment.
🔹 Hands-On Challenge
- Create a multi-container Compose app (web + db + cache).
- Add deploy settings for Swarm (replicas, update_config).
- Deploy it using
docker stack deployacross multiple nodes. - Test scaling, rolling updates, and secret usage.
✅ Next Episode: Episode 25 — Docker Troubleshooting & Debugging: Common Issues & Fixes — learn to identify and solve real-world container problems efficiently.
This content originally appeared on DEV Community and was authored by Yash Sonawane
Yash Sonawane | Sciencx (2025-09-15T02:26:00+00:00) Docker Series: Episode 24 — Docker Compose + Swarm Integration: Multi-Host Deployments 🌍. Retrieved from https://www.scien.cx/2025/09/15/docker-series-episode-24-docker-compose-swarm-integration-multi-host-deployments-%f0%9f%8c%8d/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.