Episode 13: Docker Compose Advanced (Scaling & Multi-Env Setup)



This content originally appeared on DEV Community and was authored by Yash Sonawane

In this episode, we’ll push Docker Compose beyond the basics and explore advanced use cases for real-world projects.

🔹 Topics Covered:

  1. Scaling Services
  • Using docker-compose up --scale to run multiple instances of a service.
  • Load balancing between containers.
  1. Multiple Environment Files
  • Managing .env.dev, .env.prod, .env.staging for different setups.
  • Switching environments easily with overrides.
  1. Compose Override Files
  • Using docker-compose.override.yml for local development tweaks.
  • Keeping production and dev configs clean.
  1. Networking in Compose
  • Custom networks for microservices.
  • Communication across multiple Compose projects.
  1. Best Practices
  • Avoid hardcoding values → use env variables.
  • Keep secrets outside Compose files.

🔹 Hands-On Example:

  • Create a docker-compose.yml for a Node.js + Redis app.
  • Scale Redis instances and see load balancing in action.
  • Use different .env files for dev and prod.

🔹 Quick Commands:

# Scale a service
 docker-compose up --scale web=3

# Use a specific env file
 docker-compose --env-file .env.prod up

# Run with override
 docker-compose -f docker-compose.yml -f docker-compose.prod.yml up -d


This content originally appeared on DEV Community and was authored by Yash Sonawane