Docker Compose & local environments
Multi-service dev stacks: networks, volumes, healthcheck-gated depends_on, profiles, override files. The fastest path from laptop to "works like prod".
About 20 min read3-question knowledge check
The mental model
If a Dockerfile is a recipe for one dish, Compose is the menu for the whole meal, plus the seating plan. It answers three questions that a single container cannot: which services exist, how they find each other, and what has to be ready before what.
Three ideas carry almost everything:
- **Networks are the dining room.** Compose puts every service on a shared network and runs a DNS server on it. Inside that network, the service *name* is the hostname — the API reaches Postgres at
db:5432, not at an IP address it had to discover.ports:is a hatch through the wall to your laptop; services talking to each other never need it. - **Volumes are the pantry.** A container's writable layer dies with the container. A named volume outlives it, which is why your database keeps its data across
docker compose down. A bind mount is a window onto a host directory — perfect for live-reloading source code in development, wrong for production. - **
depends_onwith a healthcheck is the "is the kitchen ready?" check.** Plaindepends_ononly orders starts; it does not wait for readiness. A database container is "started" several seconds before it accepts connections, which is why so many stacks fail on first boot.
Why this matters for DevOps: Compose is the fastest honest way to get "works like prod" onto a laptop and into CI. New engineers run one command instead of following a twelve-step README, and integration tests get real Postgres and Redis instead of mocks.
The full lesson continues with 15 more sections
- Deep dive
- Internal architecture
- Real-world use cases
- Best practices
- Common mistakes
- Performance
- Security
- Production troubleshooting
- Advantages & disadvantages
- Alternatives
- Interview expectations
- Interview questions
- Facts to remember
- Cheat sheet
- Quick revision