docker-compose-patterns
Skill1 starsChanged 11 days agoMITView on GitHub
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.
- Reads credentials
1 other project uses a version of this.
Adopted by
Most recently taken up by
- docker/skillsword for word, first seen Nov 5, 2026
Other versions1 project uses a version of this.
Word for word · 1
- docker/skills★ 618100% same
Edited · 0
None found.
Wrote their own version · 0
None found.
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository58 other files it gives its agents.
- AGENTS.mdAGENTS.md
- .agents/skills/vercel-composition-patterns/AGENTS.mdAGENTS.md
- .agents/skills/vercel-react-best-practices/AGENTS.mdAGENTS.md
- .claude/skills/vercel-composition-patterns/AGENTS.mdAGENTS.md
- .claude/skills/vercel-react-best-practices/AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- .github/copilot-instructions.mdCopilot instructions
- ai-in-the-productSkill
- backend-apiSkill
- database-quickSkill
- data-ml-quickstartSkill
- debug-fastSkill
- demo-and-pitchSkill
- deploy-fastSkill
- deploy-to-vercelSkill
- docker-build-strategiesSkill
- docker-destructive-guardrailsSkill
- docker-project-foundationsSkill
- find-skillsSkill
- frontend-nextjs-vercelSkill
- git-githubSkill
- kickoffSkill
- pitch-deckSkill
- rapid-prototypeSkill
- repo-polishSkill
- security-basicsSkill
- smoke-testingSkill
- team-syncSkill
- ui-polishSkill
- vercel-composition-patternsSkill
- vercel-react-best-practicesSkill
- verification-before-doneSkill
- ai-in-the-productSkill
- backend-apiSkill
- database-quickSkill
- data-ml-quickstartSkill
- debug-fastSkill
- demo-and-pitchSkill
- deploy-fastSkill
- deploy-to-vercelSkill
- docker-build-strategiesSkill
- docker-compose-patternsSkill
- docker-destructive-guardrailsSkill
- docker-project-foundationsSkill
- find-skillsSkill
- frontend-nextjs-vercelSkill
- git-githubSkill
- kickoffSkill
- pitch-deckSkill
- rapid-prototypeSkill
- repo-polishSkill
- security-basicsSkill
- smoke-testingSkill
- team-syncSkill
- ui-polishSkill
- vercel-composition-patternsSkill
- vercel-react-best-practicesSkill
- verification-before-doneSkill
The file
Show its rules and text
We split this skill into the rules it gives an agent
29 rules. About 0 are common, 7 are distinctive, and 22 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈7
Distinctive · estimate
This author's own choices. Worth a look.
22
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 25
Do not use this skill when:
- Very specific: line 35
Use compose.yaml as the canonical filename.
- Very specific: line 40
Always pin image tags to a specific version.
- Very specific: line 42
Add container_name only when external tools need a predictable name.
- Very specific: line 46
Use depends_on with condition: service_healthy for services that must be ready before dependents start.
- Very specific: line 47
Every service listed in depends_on with a health condition must have a healthcheck defined.
- Very specific: line 48
Do not rely on depends_on without conditions — it only guarantees container start, not readiness.
- Very specific: line 52
Always add a healthcheck to database services (Postgres, MySQL, Redis, MongoDB).
- Very specific: line 53
Use the service's native client tool for health checks when available (e.g., pg_isready, redis-cli ping, mysqladmin ping).
- Distinctive: line 89
Keep the sidecar lightweight with a resource limit (32MB is sufficient for curl).
- Distinctive: line 101
Use named volumes for data that must persist across container recreations (database data, uploaded files).
- Distinctive: line 102
Use bind mounts only for development-time source code syncing.
- Distinctive: line 104
Do not mount the Docker socket unless the service genuinely requires it.
- Distinctive: line 109
When creating custom networks, prefer bridge driver and give networks descriptive names.
- Very specific: line 110
Use the top-level networks: key to define all custom networks.
- Very specific: line 114
Use environment: for non-sensitive values that are few in number.
- Very specific: line 115
Use env_file: pointing to a .env file for longer lists of variables.
- Very specific: line 116
Never hardcode secrets (passwords, API keys) directly in compose.yaml.
- Very specific: line 117
When defaults are needed in the environment: block for local development, use variable substitution with fallbacks: …
- Very specific: line 118
Add .env to .gitignore.
- Very specific: line 122
Use compose.override.yaml for development-only settings.
- Distinctive: line 123
Put bind mounts for source code, debug ports, and development environment variables in the override file.
- Very specific: line 124
Use develop.watch for file-syncing and auto-rebuild in development when supported.
- Very specific: line 125
Keep production-oriented settings in the base compose.yaml and override only what changes for development.
- Very specific: line 129
Prefer develop.watch over manual bind mounts for development workflows.
- Very specific: line 130
Use action: sync for files that should be copied into the container on change (source code).
- Very specific: line 131
Use action: rebuild for files that require a full image rebuild (dependency files like package.json, requirements.txt).
- Very specific: line 132
Use action: sync+restart for configuration files that need a process restart.
- Very specific: line 142
If the goal is only to restart services or reclaim containers/networks, use docker compose down (no -v) or docker compose restart instead — …
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Docker Compose Patterns
Overview
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.
When to use this skill
Activate this skill when:
- Creating a new
compose.yamlfor a project - Adding or modifying services in an existing Compose file
- Setting up development overrides with
compose.override.yaml - Debugging service startup ordering or connectivity issues
Do not use this skill when
Do not use this skill when:
- The project has no Docker setup yet and the main need is an initial scaffold
- The main task is writing or optimizing a
Dockerfile - The main task is improving build caching, image size, or runtime user configuration
Core guidance
File naming
Use compose.yaml as the canonical filename. Do not use docker-compose.yml or docker-compose.yaml — those are legacy names.
Service definitions
- Give services clear, lowercase names that reflect their role:
web,db,cache,worker. - Always pin image tags to a specific version. Never use
latestor omit the tag. - Set
restart: unless-stoppedfor long-running infrastructure services and non-development deployments. - Add
container_nameonly when external tools need a predictable name. Otherwise, let Compose generate names.
Dependency modeling
- Use
depends_onwithcondition: service_healthyfor services that must be ready before dependents start. - Every service listed in
depends_onwith a health condition must have ahealthcheckdefined. - Do not rely on
depends_onwithout conditions — it only guarantees container start, not readiness.
Health checks
- Always add a
healthcheckto database services (Postgres, MySQL, Redis, MongoDB). - Use the service's native client tool for health checks when available (e.g.,
pg_isready,redis-cli ping,mysqladmin ping). - Set reasonable
interval,timeout,retries, andstart_periodvalues. Start with:interval: 5s,timeout: 3s,retries: 3,start_period: 10s.
Health checks for distroless or scratch images
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.22.0
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: 32MKey points:
- The sidecar must stay alive with
entrypoint: ["sleep", "infinity"]so Compose can execute the healthcheck inside it. network_mode: "service:api"makeslocalhostinside the sidecar resolve to the api container's loopback — no extra networking needed.- Keep the sidecar lightweight with a resource limit (32MB is sufficient for curl).
- Services that depend on
apibeing ready should reference the sidecar, not the api directly:
worker:
depends_on:
api-health:
condition: service_healthyVolumes
- Use named volumes for data that must persist across container recreations (database data, uploaded files).
- Use bind mounts only for development-time source code syncing.
- Define all named volumes in the top-level
volumes:key. - Do not mount the Docker socket unless the service genuinely requires it.
Networks
- For single-application stacks, the default network is sufficient. Do not create custom networks unless you need isolation between service groups.
- When creating custom networks, prefer bridge driver and give networks descriptive names.
- Use the top-level
networks:key to define all custom networks.
Environment variables
- Use
environment:for non-sensitive values that are few in number. - Use
env_file:pointing to a.envfile for longer lists of variables. - Never hardcode secrets (passwords, API keys) directly in
compose.yaml. Useenv_file:or Docker secrets. - When defaults are needed in the
environment:block for local development, use variable substitution with fallbacks:${DB_PASSWORD:-postgres}. Never write bare plaintext values for password fields. - Add
.envto.gitignore.
Development overrides
- Use
compose.override.yamlfor development-only settings. Compose loads it automatically alongsidecompose.yaml. - Put bind mounts for source code, debug ports, and development environment variables in the override file.
- Use
develop.watchfor file-syncing and auto-rebuild in development when supported. - Keep production-oriented settings in the base
compose.yamland override only what changes for development.
Compose Watch
- Prefer
develop.watchover manual bind mounts for development workflows. - Use
action: syncfor files that should be copied into the container on change (source code). - Use
action: rebuildfor files that require a full image rebuild (dependency files likepackage.json,requirements.txt). - Use
action: sync+restartfor configuration files that need a process restart.
Destructive commands
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 prunerun against a Compose project's volumes — deletes volumes directly. For the standalone case (no Compose project in play), seedocker-destructive-guardrailsinstead. A volume referenced viaexternal: trueisn't managed by the Compose project either (down -vwon't touch it) — treat it as the standalone case too: rundocker volume rmwithout-ffirst, 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.
Related skills
- For first-time Docker project scaffolding and baseline file creation, use
docker-project-foundations. - For Dockerfile internals, build caching, multi-stage builds, and
.dockerignore, usedocker-build-strategies. - For destructive Docker CLI commands outside Compose (
docker system prune,docker rm -f, image/network/builder pruning, standalone volume deletion) and a cross-product index of destructive-command guardrails, usedocker-destructive-guardrails.
References
references/service-dependencies.md— Detailed guidance ondepends_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
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
scripts/verify-compose.sh— Validates the Compose project in the current directory withdocker compose config --quiet, without printing resolved configuration. Run it from the project root (the directory that containscompose.yaml), with the script path resolved under this skill's directory:
Replacebash "<skill-dir>/scripts/verify-compose.sh" [--help]<skill-dir>with the absolute path of the folder that contains thisSKILL.md; thescripts/path is relative to that folder, not to the project. Do not change into the skill directory first: the script validates whatever Compose project is in the current directory. If the skill directory cannot be resolved, rundocker compose config --quietdirectly. Exit status is0when the Compose configuration is valid or help is requested, the non-zero status fromdocker compose config --quietwhen validation fails, and2for invalid arguments. Plaindocker compose configcan expose interpolated andenv_filecredentials in tool output or logs; use quiet validation by default. Compose warnings and errors are still emitted and may contain sensitive details.
Checks
checks/verification.md— Detailed verification runbook for manual review.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

