Docker Compose for Development Environments: Services, Profiles and Watch
Use Docker Compose for reproducible local development: multi-service stacks, healthchecks and depends_on, profiles, compose watch for live sync, and env file...
Published December 2, 2026
A new developer should be able to clone a repository and have the whole stack (API, database, cache, queue, mail catcher) running with one command. Docker Compose makes that practical, and recent features like compose watch and profiles make it pleasant for day-to-day development, not just demos.
The concept
A compose.yaml file declares services, networks and volumes. Each service gets a DNS name on the project network, so the API connects to postgres:5432 rather than localhost. Healthchecks plus depends_on with condition: service_healthy ensure dependencies are actually ready before dependent services start, avoiding flaky startup races.
Profiles let optional services (an admin UI, a metrics stack, a worker) start only when requested. Compose watch syncs source changes into running containers or rebuilds them when dependency files change, giving fast feedback without bind-mount performance problems on macOS and Windows. Environment variables come from .env files and per-service env_file entries.
A typical dev stack
Useful features
| Feature | Use |
|---|---|
| depends_on + service_healthy | Start API only when DB accepts connections |
| profiles | Optional services: docker compose --profile tools up |
| develop.watch | Sync code / rebuild on dependency changes |
| named volumes | Persist database data between runs |
| env_file / .env | Configuration without hard-coding |
| compose.override.yaml | Personal or environment-specific tweaks |
The developer workflow
- git clone repo && cp .env.example .env
- docker compose up -d (or docker compose watch)
- docker compose exec api npm run migrate
- Open http://localhost:3000
- docker compose down (add -v to wipe data)
Practical examples
compose.yaml with healthchecks and watch
API waits for a healthy database and syncs code changes.
services:
api:
build: .
ports: ["3000:3000"]
env_file: .env
depends_on:
postgres: { condition: service_healthy }
develop:
watch:
- action: sync
path: ./src
target: /app/src
- action: rebuild
path: package-lock.json
postgres:
image: postgres:17
environment: { POSTGRES_PASSWORD: dev, POSTGRES_DB: app }
volumes: [pgdata:/var/lib/postgresql/data]
healthcheck:
test: ["CMD-SHELL", "pg_isready -U postgres"]
interval: 5s
retries: 10
mailpit:
image: axllent/mailpit
ports: ["8025:8025"]
profiles: [tools]
volumes:
pgdata: {}Everyday commands
Start, watch, inspect, clean up.
docker compose watch # start and live-sync
docker compose --profile tools up -d
docker compose logs -f api
docker compose exec postgres psql -U postgres app
docker compose down -v # remove containers and volumesRun tests in the same environment
Consistent results across machines and CI.
docker compose run --rm api npm testCommon mistakes
- depends_on without healthchecks, so the API starts before the DB is ready.
- Connecting to localhost from inside a container instead of the service name.
- Bind-mounting node_modules from the host and mixing OS-specific binaries.
- Committing real secrets in .env files.
Key takeaways
- Compose gives one-command, reproducible dev stacks.
- Use healthchecks with depends_on conditions.
- Profiles for optional services; watch for fast feedback.
- Use service names for networking inside the project.
FAQ
Should production use Compose?
Compose can run small single-host deployments, but multi-host production usually uses Kubernetes, ECS or similar orchestrators.
Is docker-compose (with a hyphen) still needed?
The modern Compose v2 is the docker compose subcommand; the old Python docker-compose is deprecated.
How do I seed the database?
Mount SQL files into /docker-entrypoint-initdb.d for official database images, or run a seed command after startup.