Docker Compose Cheat Sheet: Commands & compose.yaml Keys
The docker compose commands and compose.yaml keys in one reference.
Lifecycle commands and the service definition keys for multi-container apps.
Commands
| Command | Does |
|---|---|
| docker compose up -d | Start in background |
| docker compose up --build | Rebuild then start |
| docker compose down -v | Stop + remove volumes |
| docker compose ps | List services |
| docker compose logs -f svc | Follow a service log |
| docker compose exec svc sh | Shell into a service |
| docker compose run --rm svc cmd | One-off command |
Service keys
| Key | Purpose |
|---|---|
| image / build | Pull image or build from context |
| ports | host:container port maps |
| environment / env_file | Env vars |
| volumes | Bind/named mounts |
| depends_on | Start order (+ condition) |
| healthcheck | Liveness probe |
| networks | Attach to networks |
| restart | no / on-failure / always |
Example
compose.yaml
services:
api:
build: .
ports: ["8080:8080"]
env_file: .env
depends_on:
db: { condition: service_healthy }
db:
image: postgres:16
healthcheck:
test: ["CMD", "pg_isready", "-U", "${POSTGRES_USER}"]
interval: 5sKey takeaways
- depends_on with condition: service_healthy waits for readiness, not just start.
- down -v also drops named volumes - omit -v to keep data.
- run --rm is ideal for one-off tasks like migrations.
Related guides
Docker Cheat Sheet: Commands, Dockerfile & ComposeA Docker cheat sheet - build, run, images, volumes, networks, Dockerfile instructions, and compose commands f…
Docker CLI Cheat Sheet: Every Command You Use DailyA Docker CLI cheat sheet - run, build, ps, exec, logs, images, volumes, networks, and the prune commands for…
Dockerfile Instructions Cheat Sheet: Every Keyword ExplainedA Dockerfile instructions cheat sheet - FROM, RUN, COPY, ENV, ARG, ENTRYPOINT, CMD, HEALTHCHECK, and multi-st…