Use this skill when creating, modifying, or debugging Docker Compose configurations, even if the user just says they need to wire services together, add a database to their stack, or set up a local development environment with multiple containers. Covers service definitions, health checks, dependency ordering, volumes, networks, environment variables, and development overrides.
npx skills add https://github.com/docker/skills --skill docker-compose-patterns
This skill provides rules for creating, reviewing, and debugging Docker Compose configurations. Use it when the main artifact is compose.yaml or compose.override.yaml and the task is about service wiring rather than image-build internals.
Activate this skill when:
compose.yaml for a projectcompose.override.yamlDo not use this skill when:
DockerfileUse compose.yaml as the canonical filename. Do not use docker-compose.yml or docker-compose.yaml — those are legacy names.
web, db, cache, worker.latest or omit the tag.restart: unless-stopped for long-running infrastructure services and non-development deployments.container_name only when external tools need a predictable name. Otherwise, let Compose generate names.depends_on with condition: service_healthy for services that must be ready before dependents start.depends_on with a health condition must have a healthcheck defined.depends_on without conditions — it only guarantees container start, not readiness.healthcheck to database services (Postgres, MySQL, Redis, MongoDB).pg_isready, redis-cli ping, mysqladmin ping).interval, timeout, retries, and start_period values. Start with: interval: 5s, timeout: 3s, retries: 3, start_period: 10s.Distroless, scratch-based, and hardened images contain no shell, curl, or wget. Do not bake tools into these images — that defeats their purpose. Instead, use a healthcheck sidecar that shares the application's network namespace:
services:
api:
build:
context: .
target: runtime # distroless / hardened image
ports:
- "8080:8080"
# No healthcheck here — the image has no tools to run one
api-health:
image: curlimages/curl:8
network_mode: "service:api" # shares api's localhost
entrypoint: ["sleep", "infinity"] # keep sidecar alive for healthcheck
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:8080/health"]
interval: 30s
timeout: 5s
retries: 3
start_period: 45s
deploy:
resources:
limits:
memory: 32M
Key points:
entrypoint: ["sleep", "infinity"] so Compose can execute the healthcheck inside it.network_mode: "service:api" makes localhost inside the sidecar resolve to the api container's loopback — no extra networking needed.api being ready should reference the sidecar, not the api directly: worker:
depends_on:
api-health:
condition: service_healthy
volumes: key.networks: key to define all custom networks.environment: for non-sensitive values that are few in number.env_file: pointing to a .env file for longer lists of variables.compose.yaml. Use env_file: or Docker secrets.environment: block for local development, use variable substitution with fallbacks: ${DB_PASSWORD:-postgres}. Never write bare plaintext values for password fields..env to .gitignore.compose.override.yaml for development-only settings. Compose loads it automatically alongside compose.yaml.develop.watch for file-syncing and auto-rebuild in development when supported.compose.yaml and override only what changes for development.develop.watch over manual bind mounts for development workflows.action: sync for files that should be copied into the container on change (source code).action: rebuild for files that require a full image rebuild (dependency files like package.json, requirements.txt).action: sync+restart for configuration files that need a process restart.Some Compose commands delete data irreversibly. Before running any of the following, state exactly which data will be deleted and get explicit confirmation from the user — do not run them as a side effect of debugging, restarting, or "cleaning up" a stack:
docker compose down -v / docker compose down --volumes — deletes named volumes, including database data.docker volume rm / docker volume prune run against a Compose project's volumes — deletes volumes directly. For the standalone case (no Compose project in play), see docker-destructive-guardrails instead. A volume referenced via external: true isn't managed by the Compose project either (down -v won't touch it) — treat it as the standalone case too: run docker volume rm without -f first, and get explicit confirmation before deleting it.docker compose rm -v — deletes anonymous volumes attached to removed containers.If the goal is only to restart services or reclaim containers/networks, use docker compose down (no -v) or docker compose restart instead — these leave named volumes intact.
docker-project-foundations..dockerignore, use docker-build-strategies.docker system prune, docker rm -f, image/network/builder pruning, standalone volume deletion) and a cross-product index of destructive-command guardrails, use docker-destructive-guardrails.references/service-dependencies.md — Detailed guidance on depends_on, health check patterns for common databases, and startup ordering strategies.references/volumes-and-networks.md — Patterns for volume mounts, named volumes, bind mounts, and network configuration.assets/compose-web-app.yaml — Complete multi-service web app (app + Postgres + Redis) with health checks, dependencies, and named volumes.assets/compose-dev-override.yaml — Development override showing bind mounts, debug ports, and Compose Watch configuration.assets/bad-vs-good.md — Before/after comparisons of common Compose mistakes and their fixes.scripts/verify-compose.sh — Validates compose.yaml with docker compose config --quiet, without printing resolved configuration. bash scripts/verify-compose.sh [--help]
Exit status is 0 when the Compose configuration is valid or help is requested, the non-zero status from docker compose config --quiet when validation fails, and 2 for invalid arguments. Plain docker compose config can expose interpolated and env_file credentials in tool output or logs; use quiet validation by default. Compose warnings and errors are still emitted and may contain sensitive details.
checks/verification.md — Detailed verification runbook for manual review.Take docker/docker-compose-patterns from the repository into ~/.claude/skills for personal
use, or into .claude/skills inside a project.
The agent identifies a skill by the name field in its header. Two skills with the
same name cannot sit side by side — one of them will be ignored.