docker-compose-guide
Skill4 starsChanged 9 months agoMITView on GitHub
Guide for writing Docker Compose files with services, networks, volumes, health checks, and environment management. Use when the user creates or modifies docker-compose.yml, asks about multi-container setups, local development environments, or service orchestration. Trigger whenever Docker Compose, multi-container, or local dev environment is mentioned.
- Reads credentials
In this repository78 other files it gives its agents.
- AGENTS.mdAGENTS.md
- rules/agents.mdAGENTS.md
- .github/copilot-instructions.mdCopilot instructions
- .cursor/rules/claude-initial-setup.mdcCursor rule
- parallel-task-executionSkill
- subagent-patternsSkill
- task-coordinationSkill
- agent-communicationSkill
- context-managementSkill
- multi-agent-orchestrationSkill
- deploy-strategiesSkill
- github-actions-guideSkill
- pipeline-patternsSkill
- anthropic-sdk-guideSkill
- prompt-engineeringSkill
- tool-use-patternsSkill
- automated-review-setupSkill
- pr-standardsSkill
- review-checklistSkill
- file-organizationSkill
- immutability-patternsSkill
- naming-conventionsSkill
- branching-strategySkill
- commit-conventionsSkill
- pr-workflowSkill
- migration-patternsSkill
- query-optimizationSkill
- schema-design-guideSkill
- error-tracingSkill
- log-analysisSkill
- systematic-debuggingSkill
- django-admin-customizationSkill
- django-orm-masterySkill
- drf-api-patternsSkill
- dockerfile-best-practicesSkill
- multi-stage-buildsSkill
- express-error-handlingSkill
- middleware-patternsSkill
- rest-api-nodeSkill
- async-fastapiSkill
- dependency-injection-fastapiSkill
- pydantic-validationSkill
- concurrency-patterns-goSkill
- error-handling-goSkill
- idiomatic-goSkill
- automation-triggersSkill
- hook-recipesSkill
- pre-post-hooksSkill
- junit-testingSkill
- maven-gradle-guideSkill
- spring-boot-patternsSkill
- mcp-resource-patternsSkill
- mcp-server-creationSkill
- mcp-tool-designSkill
- context-optimizationSkill
- knowledge-persistenceSkill
- memory-patternsSkill
- caching-strategiesSkill
- lazy-loading-patternsSkill
- profiling-guideSkill
- The first 60 shown.
The file
We split this skill into the rules it gives an agent
7 rules. About 0 are common, 3 are distinctive, and 4 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈3
Distinctive · estimate
This author's own choices. Worth a look.
4
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- could be automatic: a setting could enforce it
- Distinctive: line 12
Write well-structured Docker Compose configurations for local development, testing, and production-like environments with proper …
- Very specific: line 67
Use depends_on with condition: service_healthy to ensure proper startup order.
- Distinctive: line 98
Use profiles to group services that are only needed in specific scenarios.
- Very specific: line 135
Start with profiles: docker compose --profile debug --profile monitoring up
- Very specific: line 158
Use .env files for defaults and environment for overrides.
- Very specific: line 184
Hardcoding passwords in compose file: Use env_file, Docker secrets, or environment variables.
- Distinctive: line 187
Exposing database ports in production: Only expose database ports for local development.
≈ “Common” is an estimate: at least 1 in 5 of the 213,895 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 Guide
Write well-structured Docker Compose configurations for local development, testing, and production-like environments with proper networking, health checks, and dependency management.
When to Use
- User creates or edits docker-compose.yml
- User sets up a local development environment with multiple services
- User asks about service dependencies, networking, or volumes
- User needs to coordinate database, cache, and app containers
- User asks about environment variable management in Docker
Core Patterns
Service Definition with Health Checks
Define services with explicit health checks so dependent services wait for readiness, not just container start.
services:
postgres:
image: postgres:16-alpine
environment:
POSTGRES_DB: myapp
POSTGRES_USER: myapp
POSTGRES_PASSWORD_FILE: /run/secrets/db_password
volumes:
- postgres_data:/var/lib/postgresql/data
- ./init.sql:/docker-entrypoint-initdb.d/init.sql:ro
ports:
- "5432:5432"
healthcheck:
test: ["CMD-SHELL", "pg_isready -U myapp -d myapp"]
interval: 5s
timeout: 3s
retries: 5
start_period: 10s
networks:
- backend
redis:
image: redis:7-alpine
command: redis-server --maxmemory 256mb --maxmemory-policy allkeys-lru
volumes:
- redis_data:/data
healthcheck:
test: ["CMD", "redis-cli", "ping"]
interval: 5s
timeout: 3s
retries: 5
networks:
- backendApplication Service with Dependencies
Use depends_on with condition: service_healthy to ensure proper startup order.
services:
api:
build:
context: .
dockerfile: Dockerfile
target: development
volumes:
- .:/app
- /app/node_modules
ports:
- "3000:3000"
environment:
DATABASE_URL: postgres://myapp:secret@postgres:5432/myapp
REDIS_URL: redis://redis:6379
NODE_ENV: development
depends_on:
postgres:
condition: service_healthy
redis:
condition: service_healthy
networks:
- backend
- frontend
restart: unless-stoppedProfiles for Optional Services
Use profiles to group services that are only needed in specific scenarios.
services:
app:
build: .
ports:
- "3000:3000"
mailhog:
image: mailhog/mailhog:latest
ports:
- "1025:1025"
- "8025:8025"
profiles:
- debug
pgadmin:
image: dpage/pgadmin4:latest
environment:
PGADMIN_DEFAULT_EMAIL: admin@local.dev
PGADMIN_DEFAULT_PASSWORD: admin
ports:
- "5050:80"
profiles:
- debug
prometheus:
image: prom/prometheus:latest
volumes:
- ./prometheus.yml:/etc/prometheus/prometheus.yml:ro
ports:
- "9090:9090"
profiles:
- monitoringStart with profiles: docker compose --profile debug --profile monitoring up
Networks and Volumes
Explicitly define networks for service isolation and named volumes for data persistence.
networks:
frontend:
driver: bridge
backend:
driver: bridge
internal: true # No external access
volumes:
postgres_data:
driver: local
redis_data:
driver: localEnvironment Variable Management
Use .env files for defaults and environment for overrides. Never commit secrets.
services:
api:
env_file:
- .env
- .env.local # Overrides .env, not committed
environment:
LOG_LEVEL: ${LOG_LEVEL:-info}
APP_VERSION: ${APP_VERSION:?APP_VERSION is required}Example .env file:
# .env (committed, defaults only)
COMPOSE_PROJECT_NAME=myapp
LOG_LEVEL=info
NODE_ENV=developmentAnti-Patterns
- Using
depends_onwithout health checks:depends_ononly waits for container start, not service readiness. Always pair withcondition: service_healthy. - Bind-mounting node_modules: Overwriting container node_modules with host volume causes platform mismatches. Use anonymous volume exclusion:
/app/node_modules. - Hardcoding passwords in compose file: Use
env_file, Docker secrets, or environment variables. Never commit credentials. - Using
links: Links are legacy. Use Docker networks instead -- services on the same network resolve each other by service name. - Not using named volumes: Anonymous volumes are hard to manage and back up. Always use named volumes for persistent data.
- Exposing database ports in production: Only expose database ports for local development. In production, keep databases on internal networks.
Quick Reference
# Start all services
docker compose up -d
# Start with specific profiles
docker compose --profile debug up -d
# Rebuild and start
docker compose up -d --build
# View logs
docker compose logs -f api
# Scale a service
docker compose up -d --scale worker=3
# Stop and remove volumes
docker compose down -v
# Execute command in running container
docker compose exec api sh
# Run one-off command
docker compose run --rm api npm testDoes 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.

