Use it to run multi-container applications on a single host.
Docker Compose Basics
Docker Compose defines services, networks and volumes in compose.yaml and runs them together with docker compose.
1. docker compose config — valid?
2. docker compose up -d.
3. docker compose ps and logs.
4. Healthchecks passing?
5. Persist data in named volumes.
compose.yaml → network + volumes → services
Context & applicabilityCommon mistakes · platform/version boundaries
Operational reference
Fast context before you go deeper.
Verification & Troubleshooting
Start with the observed symptom, prove the nearest boundary, and move outward only when the current state is understood.
Use the operational verification above to establish the expected state.
Capture the concrete output, symptom, packet, log or counter before changing anything.
Step 1 How to verify Verify boundary
Validate with docker compose config before deploying. After up -d, confirm every service is running and healthy. Test that services reach each other by service name.
Step 2 Common failures Narrow the fault
depends_on without a health condition only orders startup; it does not wait for readiness. Running compose from another directory creates a second project with the same services. Secrets placed directly in environment entries end up in docker inspect output.
Services resolve each other by name. Use .env for variables and depends_on with healthchecks. docker compose config shows the merged result.
docker compose config— merged configurationdocker ps -a— containers and exit codesdocker logs <c>— container outputdocker inspect <c>— config, mounts, network, state
ReferenceWhat it is1 section · depth on demand
How it works
Compose names resources with the project name (directory name by default). It creates networks and volumes first, then containers in dependency order. depends_on with condition: service_healthy waits for a healthcheck to pass.
ReferenceImportant terms & boundaries2 sections · depth on demand
In depth
Compose turns one YAML file into a named project: networks, volumes and containers labelled with the project name, by default the directory name.
Startup order vs readiness
services:
db:
image: postgres:17
healthcheck:
test: ["CMD-SHELL", "pg_isready -U app"]
interval: 5s
retries: 10
api:
image: myapi:1.4
depends_on:
db: { condition: service_healthy }
Plain depends_on: [db] only starts db first; condition: service_healthy waits for its health check to pass.
Configuration layering
| Mechanism | Use |
|---|---|
.env in the project directory | Variable values for ${VAR} interpolation |
env_file: | Environment variables passed into a container |
compose.override.yaml | Applied automatically on top of compose.yaml (local dev changes) |
-f a.yaml -f b.yaml | Explicit layering, later files win |
profiles: | Optional services started only with --profile |
docker compose config prints the fully merged and interpolated result; check it before deploying.
Worked update of one service
docker compose pull api
docker compose up -d --no-deps api # recreate only api
docker compose ps
docker compose logs -f --tail=50 api
up -d only recreates containers whose configuration or image changed; volumes are kept unless down -v is used.
Common mistakes
- Secrets in the compose file.
ReferenceConfiguration & state1 section · depth on demand
Compose example and commands
services:
web:
image: nginx:1.27
ports: ["8080:80"]
depends_on: { api: { condition: service_healthy } }
api:
image: myapi:1.4
environment: [DB_HOST=db]
healthcheck: { test: ["CMD", "curl", "-f", "http://localhost:8000/health"], interval: 10s }
db:
image: postgres:17
volumes: [pgdata:/var/lib/postgresql/data]
volumes: { pgdata: {} }
docker compose up -d, docker compose ps, docker compose logs -f api, docker compose down (add -v only to delete volumes). Documented example, not captured output.
Additional reference context Scope · expected state · examples · history · terminology Open only when you need the supporting context
Terms & aliases
Hover a linked term for a quick definition; click it to open its glossary entry. Aliases are other names that find this Topic in search.