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
Top comments (0)