DEV Community

Bhaskar Sharma
Bhaskar Sharma

Posted on

๐Ÿš€ Day 10 of My DevOps Journey: Docker Compose โ€” Multi-Container Apps Made Easy

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)