Docker Compose for Real Projects
You know how to run a single container. You've typed docker run enough times that it doesn't scare you anymore. But the moment you try to run a real app - the kind with an API, a database, and maybe a cache - you discover that "real" means several containers, all running at once, all needing to find each other. Suddenly you've got four terminal tabs open, you're copying long docker run flags between them, and one wrong --network argument means the API can't see the database.
That's the wall this guide gets you over. Docker Compose lets you describe your entire stack - every service, its image, its ports, its environment, how they connect - in one file, and bring the whole thing up (or down) with one command. This is how teams actually run things. (This very project runs on Compose.)
How to read this
- Already know single-container Docker and want the file format fast? Skip to Phase 2: The compose file - it's the annotated
docker-compose.ymlyou came for. - Want it to finally make sense? Read in order. Phase 1 installs the mental model, Phase 2 builds a real stack, and Phase 3 covers the networking, data, and dev-vs-prod realities that bite people later.
The phases
- Why One Container Isn't Enough - what a "stack" really is, why managing it by hand hurts, and the one idea Compose is built on.
- The compose file - services, images vs build, ports, environment,
depends_on, and named volumes - with a realweb + db + cachefile and the transcripts of bringing it up, watching logs, and tearing it down. - Networking, Volumes & Dev Workflow - how services reach each other by name, how to keep your database's data, live-reload in dev, and the two traps (
depends_onreadiness, and shipping dev config to prod).
This guide assumes you're comfortable with one container at a time -
docker run, images, ports. If any of that is fuzzy, read Docker Without the Magic first; everything here builds on it. Deep production topics - orchestration across many machines, secrets management, multi-stage build tuning - are deliberately left for a follow-up; this guide is about running a real multi-service stack on one machine, cleanly.
Related: Docker Without the Magic · Environment Variables & Config