Hello dev.to community! 👋
Yesterday, I explored Dockerfiles & Image Building — the foundation of turning source code into lightweight, portable containers. Today, I’m diving into Docker Compose — the tool that makes running multi-container applications a breeze. 🐳
🔹 Why Docker Compose Matters
In real-world projects, apps are rarely a single container. Think about it:
A frontend app + backend API + database.
Each service in its own container.
Compose manages them together with just one command.
With Docker Compose, you can:
Define multi-container apps in a single docker-compose.yml.
Manage lifecycle (start, stop, rebuild) easily.
Ensure consistent environments across dev, test, and prod.
🧠 Core Concepts I’m Learning
📄 docker-compose.yml basics
services: → define each container (e.g., web, db).
build: → build image from Dockerfile.
ports: → map container ports to host.
volumes: → persist data (important for databases).
depends_on: → define container startup order.
🔧 Example: Node.js + MongoDB App
docker-compose.yml
version: “3.8”
services:
web:
build: .
ports:
– “3000:3000”
depends_on:
– mongo
mongo:
image: mongo:6
volumes:
– mongo-data:/data/db
volumes:
mongo-data:
👉 Run the app:
docker-compose up -d
👉 Stop the app:
docker-compose down
🛠️ Mini Use Cases in DevOps
Run microservices locally with all dependencies.
Spin up test environments on demand.
Standardize environments for developers.
Make CI/CD pipelines reproducible.
⚡ Pro Tips
Use .env file to manage secrets & environment variables.
Always mount volumes for databases → avoid data loss.
Use docker-compose -f for multiple configs (dev, staging, prod).
Combine with Docker Swarm/Kubernetes later for production scaling.
🧪 Hands-on Mini-Lab (Try this!)
1️⃣ Write a docker-compose.yml for a Python Flask app + Redis.
2️⃣ Run docker-compose up -d.
3️⃣ Visit the app in your browser → http://localhost:5000
🎉
4️⃣ Scale the service → docker-compose up –scale web=3 🚀
🎯 Key Takeaway
Docker Compose makes it simple to run and manage multi-container apps — an essential step before moving to advanced orchestration with Kubernetes.
🔜 Tomorrow (Day 11)
I’ll explore Infrastructure as Code with Terraform — automating cloud resources. ☁️
🔖 #Docker #DevOps #Containers #DockerCompose #CICD #DevOpsJourney #CloudNative #Automation #SRE #OpenSource