Docker Compose simplifies local development by defining your entire stack - database, cache, application server - in a single YAML file. Instead of a README with 47 manual setup steps, new developers run one command and have a working environment in minutes.
The Setup
Here is a real-world compose file for a typical web application with PostgreSQL, Redis, and a Node.js app:
version: '3.8'
services:
db:
image: postgres:16
environment:
POSTGRES_DB: myapp
POSTGRES_USER: dev
POSTGRES_PASSWORD: devpass
ports:
- '5432:5432'
volumes:
- pgdata:/var/lib/postgresql/data
redis:
image: redis:7-alpine
ports:
- '6379:6379'
app:
build: .
ports:
- '3000:3000'
depends_on:
- db
- redis
environment:
DATABASE_URL: postgres://dev:devpass@db:5432/myapp
REDIS_URL: redis://redis:6379
volumes:
- .:/app
- /app/node_modules
volumes:
pgdata:
Run `docker compose up` and everything starts. Run `docker compose down -v` to tear it all down cleanly. New developer onboarding goes from half a day to five minutes.
Best Practices for Docker Compose in Development
- **Use `depends_on` with health checks** so your app does not crash trying to connect before the database is ready - **Mount source code as a volume** for hot-reloading during development - **Exclude `node_modules`** from the mount to avoid platform-specific binary issues - **Use named volumes** for database data so it persists between restarts - **Keep development and production configurations separate** using override files
Key Takeaways
- Docker Compose reduces local environment setup from dozens of steps to a single command - Define all services (database, cache, app) in one docker-compose.yml file - Volume mounts enable hot-reloading for fast development iteration - Named volumes persist database data between container restarts - Health checks prevent application crashes during service startup - New developer onboarding becomes nearly instant with a properly configured compose file - Keep development compose files separate from production configurations