
docker-compose
Expert guidance for Docker Compose — writing production-grade compose.yml files for multi-container applications. Covers complete Compose file syntax (services, networks, volumes, secrets, configs, profiles, extends, include), service configuration (image/build, ports, environment, envfile, dependson with health checks, deploy resources, restart policies), networking in Compose (default networks, custom networks, internal networks), volume management, environment variable strategies (.env vs environment vs envfile), override files for multi-environment, profiles for optional services, and migration to Kubernetes with kompose. Use when the user asks about docker compose, docker-compose.yml, compose file, multi-container, service orchestration, compose configuration, or needs to write/modify a compose file. 使用场景:docker compose、docker-compose.yml、compose 文件、多容器、服务编排、compose 配置、dependson、profiles.
- Installs
- 131
- Last 24h
- —
- Trending rank
- —
- Security
- Not audited
Install
Works with every agent the skills CLI supports.
npx skills add https://github.com/full-stack-skills/docker-skills --skill docker-compose- 01
Install
Run the command in your project. The CLI asks which agents to install for.
- 02
Describe the task
Ask your agent for something this skill covers. It loads docker-compose automatically when relevant.
- 03
Review the result
The agent follows the SKILL.md steps, scripts and references bundled with the skill.
SKILL.md
The instructions your agent reads when the skill is triggered.
Docker Compose — 多容器编排与 Compose 文件
Expert guidance for writing production-grade Docker Compose configurations.
When to Use
ALWAYS use this skill when the user mentions:
- "docker compose", "docker-compose.yml", "compose 文件"
- "compose 怎么写", "compose 配置"
- "多容器", "multi-container", "服务编排"
- "depends_on", "profiles", "override"
- "compose network", "compose volume"
Complete File Structure
# compose.yml
name: myapp
services: # Container definitions
networks: # Network topology
volumes: # Persistent storage
secrets: # Sensitive data (Swarm)
configs: # Non-sensitive configs (Swarm)
Services — Core Configuration
services:
web:
image: myapp:${TAG:-latest} # Pull from registry
# build: . # Or build from Dockerfile
# build: # Build with options
# context: .
# dockerfile: Dockerfile.prod
container_name: myapp-web # Explicit name (optional)
hostname: web
ports:
- "8080:8080" # host:container
- "127.0.0.1:8443:443" # bind to localhost
- "8080:8080/udp" # UDP
environment:
- NODE_ENV=production
- DB_HOST=db # Service name = hostname!
# env_file: .env.production # Load from file
volumes:
- app-logs:/var/log/app # Named volume
- ./config:/etc/app:ro # Bind mount (read-only)
- /tmp/app:/tmp # Bind mount (read-write)
depends_on:
db:
condition: service_healthy # Wait for health check
redis:
condition: service_started
healthcheck:
test: ["CMD", "wget", "-qO-", "http://localhost:8080/health"]
interval: 30s
timeout: 3s
retries: 3
start_period: 10s
restart: unless-stopped
deploy: # Swarm-only
replicas: 3
resources:
limits:
cpus: '0.5'
memory: 512M
profiles: # Optional service
- debug
Networking
Default Network (Auto-Created)
# Compose auto-creates a default bridge network.
# All services can reach each other by service name.
services:
web:
ports: ["8080:8080"]
db:
# No ports exposed externally — only accessible by 'web'
Custom Networks
networks:
frontend: # Public-facing
backend:
internal: true # No external access
services:
web:
networks: [frontend, backend] # In both networks
db:
networks: [backend] # Backend only (isolated)
cache:
networks: [backend]
Environment Variables
Approaches
| Method | Where | Best For |
|---|---|---|
environment: | In compose.yml | Simple, few vars |
env_file: | External .env.prod | Many vars, env-specific |
.env file | Project root (auto-loaded) | Default values, $VARIABLE substitution |
.env File (Auto-Loaded)
# .env — auto-loaded by docker compose
TAG=v1.2.3
DB_PASSWORD=secret123
# compose.yml — uses ${TAG} and ${DB_PASSWORD}
services:
web:
image: myapp:${TAG:-latest}
db:
environment:
POSTGRES_PASSWORD: ${DB_PASSWORD}
env_file
# .env.production
DB_HOST=prod-db.example.com
DB_PORT=5432
services:
web:
env_file: .env.production
Depends On — Service Order
services:
db:
image: postgres:16-alpine
healthcheck:
test: ["CMD-SHELL", "pg_isready -U postgres"]
interval: 10s
retries: 5
web:
depends_on:
db:
condition: service_healthy # Wait for DB to be ready
redis:
condition: service_started # Wait for Redis to start
Profiles — Optional Services
services:
app:
image: myapp
debug-tools:
image: nicolaka/netshoot
command: sleep infinity
profiles: [debug] # Only starts with --profile
elasticsearch:
image: elasticsearch:8.15.0
profiles: [analytics] # Only starts with --profile
docker compose --profile debug up # Starts app + debug-tools
docker compose --profile analytics up # Starts app + elasticsearch
Multi-Environment with Override
compose.yml # Base configuration
compose.override.yml # Local dev overrides (auto-applied)
compose.prod.yml # Production overrides
# Local: compose.yml + compose.override.yml (auto)
docker compose up -d
# Production: explicit files
docker compose -f compose.yml -f compose.prod.yml up -d
Migration to Kubernetes
kompose convert -f compose.yml # Generates K8s YAML files
kubectl apply -f .
Workflow — 推荐编排流程
Step 1: 规划服务: 列出所有服务、端口、数据卷、环境变量
Step 2: 编写 compose.yml: 定义 services/networks/volumes
Step 3: 配置依赖: depends_on + condition: service_healthy
Step 4: 本地验证: docker compose up -d → docker compose ps → docker compose logs
Step 5: 生产部署: 添加 resource limits、restart policy、日志轮转 → docker compose -f compose.yml -f compose.prod.yml up -d
Gotchas — Common Pitfalls
- depends_on without healthcheck:
depends_ononly waits for container START, not READY. → Recovery: Always addcondition: service_healthy+healthcheck:block; usedocker compose psto verify health status. - Port conflict: Multiple services can't bind the same host port. → Recovery: Use different host ports or remove
ports:for internal-only services (they communicate via service name). - Bind mount paths: Relative paths are resolved from the compose file location. → Recovery: Use
./confignotconfig/; verify withdocker compose configto see resolved paths. .envfile security:.envfiles often contain secrets. → Recovery: Add.envto.gitignore; use Docker secrets for Swarm; use.env.examplewith placeholder values.docker composevsdocker-compose: Modern syntax isdocker compose(plugin). → Recovery:docker-compose(standalone binary) is deprecated; always usedocker compose(with space).
Boundary — 能力边界(适用与不适用场景)
| 分类 | 场景 | 说明 |
|---|---|---|
| ✅ 能做 | 多容器应用编排 | services/networks/volumes/secrets/configs 完整定义 |
| ✅ 能做 | 环境管理 | .env / env_file / override 文件策略 |
| ✅ 能做 | 依赖控制 | depends_on + healthcheck + profiles |
| ⚠️ 需条件 | 多主机部署 | 迁移到 Swarm(docker stack deploy)或 K8s |
| ⚠️ 需条件 | 滚动更新/自动扩缩 | Compose 不支持,需 Swarm 或 K8s |
| ❌ 超范围 | 编写 Dockerfile | 使用 docker-dockerfile |
| ❌ 超范围 | K8s 部署 | 使用 kompose convert + K8s 技能 |
| ❌ 超范围 | 云服务编排(Terraform) | IaaC 工具 |
When NOT to Use This Skill
| ❌ Skip | ✅ Use Instead |
|---|---|
| Single-container apps | docker-run |
| Writing Dockerfile | docker-dockerfile |
| Kubernetes deployment | K8s manifests / Helm charts |
| Docker basics | docker-basics |
Security & Stability
- Use
internal: truefor backend networks to prevent external access. - Never commit
.envfiles with secrets. Use CI secrets or Docker Swarm secrets. - Production Compose on single host: combine with systemd for auto-start on boot.
- Multi-host production: migrate to Swarm (
docker stack deploy) or Kubernetes.
📚 官方文档参考
| 文档 | 地址 |
|---|---|
| Docker Compose 概述 | https://docs.docker.com/compose/ |
| Compose 文件参考 | https://docs.docker.com/reference/compose-file/ |
| Compose CLI | https://docs.docker.com/reference/cli/docker/compose/ |
| 环境变量 | https://docs.docker.com/compose/environment-variables/ |
| Compose 网络 | https://docs.docker.com/compose/networking/ |
| 生产环境 Compose | https://docs.docker.com/compose/production/ |
🧭 Docker Skills Journey
📍 You are here:
docker-compose— 多容器编排
← Previous: docker-buildx / docker-networking
→ Next: docker-production / docker-cicd
FAQ
What does the docker-compose skill do?
Expert guidance for Docker Compose — writing production-grade compose.yml files for multi-container applications. Covers complete Compose file syntax (services, networks, volumes, secrets, configs, profiles, extends, include), service configuration (image/build, ports, environment, envfile, dependson with health checks, deploy resources, restart policies), networking in Compose (default networks, custom networks, internal networks), volume management, environment variable strategies (.env vs environment vs envfile), override files for multi-environment, profiles for optional services, and migration to Kubernetes with kompose. Use when the user asks about docker compose, docker-compose.yml, compose file, multi-container, service orchestration, compose configuration, or needs to write/modify a compose file. 使用场景:docker compose、docker-compose.yml、compose 文件、多容器、服务编排、compose 配置、dependson、profiles.
How do I install docker-compose?
Run npx skills add https://github.com/full-stack-skills/docker-skills --skill docker-compose in your project. The skills CLI detects the agents you use and copies the skill into the right folder. For Claude Code you can also place the skill folder at ~/.claude/skills/docker-compose/ (personal) or .claude/skills/docker-compose/ (project).
Which AI agents can use docker-compose?
Any agent that supports the open Agent Skills format (a folder with a SKILL.md file), including Claude Code, Codex, Cursor, GitHub Copilot, Gemini CLI, Windsurf, Cline, OpenCode and more.
Is docker-compose safe to install?
No partner security audit is available yet. Skills can run commands and scripts, so read the SKILL.md and any bundled files before installing.
Who maintains docker-compose?
It is published by full-stack-skills in full-stack-skills/docker-skills. It has 131 recorded installs.
More from full-stack-skills/docker-skills
docker-dockerfile
full-stack-skills/docker-skills
Open the skill to read its SKILL.md instructions.
docker-security
full-stack-skills/docker-skills
Open the skill to read its SKILL.md instructions.
docker-troubleshooting
full-stack-skills/docker-skills
Open the skill to read its SKILL.md instructions.
docker-networking
full-stack-skills/docker-skills
Open the skill to read its SKILL.md instructions.
docker-basics
full-stack-skills/docker-skills
Open the skill to read its SKILL.md instructions.
docker-buildx
full-stack-skills/docker-skills
Open the skill to read its SKILL.md instructions.
Popular devops & cloud skills
microsoft-foundry
microsoft/azure-skills
Build, deploy, evaluate, optimize, fine-tune, and manage Microsoft Foundry agents, models, and resources end to end. USE FOR: foundry, azd ai agent, azd provision/deploy, hosted agent scaffold/develop/run/deploy/troubleshoot, prompt agent create, managed harness agent create, GitHub Copilot harness agent, create agent, update agent, add tool to agent, invoke agent, agent insights, evaluate agent, batch eval, continuous eval, continuous monitoring, agent CI/CD, optimize prompt, improve prompt, optimize agent instructions, Agent Optimizer scaffold, dataset curation from traces, deploy model, model fine-tuning (SFT/DPO/RFT), Foundry project, RBAC, role assignment, permissions, quota, capacity, region, deployment failure, AI Services, create Foundry resource, knowledge index, customize deployment, onboard, availability, training-data, grader, distillation, large file upload. DO NOT USE FOR: Azure Functions, App Service, general Azure deploy (use azure-deploy), general Azure prep (use azure
azure-diagnostics
microsoft/azure-skills
Debug Azure production issues on Azure using AppLens, Azure Monitor, resource health, and safe triage. WHEN: debug production issues, troubleshoot app service, app service high CPU, app service deployment failure, troubleshoot container apps, container app 503 or target port mismatch, troubleshoot functions, function telemetry missing or stopped after a config/connection-string change, troubleshoot AKS, VM RDP, Linux SSH, VM black screen, can't connect to VM, reset VM password, NSG or firewall blocking, kubectl cannot connect, kube-system/CoreDNS failures, pod pending, crashloop, node not ready, upgrade failures, analyze logs, KQL, insights, image pull failures, cold start issues, health probe failures, resource health, root cause of errors, troubleshoot event hubs, troubleshoot service bus, messaging SDK error, AMQP connection failure, message lock lost, lock renewal during long-running processing, service bus dead letter.
azure-prepare
microsoft/azure-skills
Prepare azd-based Azure projects for deployment: generates azure.yaml, infrastructure (Bicep/Terraform), and Dockerfiles for the Azure Developer CLI (azd) workflow. USE ONLY when the user explicitly wants to use azd as the deployment tool, or the project already has an azure.yaml file. DO NOT USE FOR: non-azd deployments, Python App Service code-only deploys (use python-appservice-deploy), or cross-cloud migration (use azure-cloud-migrate). WHEN: prepare app for azd, create azure.yaml, set up azd infrastructure, modernize app for Azure with azd, deploy with azd, function app, timer trigger, service bus trigger, event-driven function, managed identity, generate Bicep, generate Terraform, create and deploy to Azure.
azure-ai
microsoft/azure-skills
Use for Azure AI: Search, Speech, OpenAI, Document Intelligence. Helps with search, vector/hybrid search, speech-to-text, text-to-speech, transcription, OCR. WHEN: AI Search, query search, vector search, hybrid search, semantic search, speech-to-text, text-to-speech, transcribe, OCR, convert text to speech.
azure-deploy
microsoft/azure-skills
Execute Azure deployments for ALREADY-PREPARED applications that have existing .azure/deployment-plan.md and infrastructure files. DO NOT use this skill when the user asks to CREATE a new application — use azure-prepare instead. This skill runs azd up, azd deploy, terraform apply, and az deployment commands with built-in error recovery. Requires .azure/deployment-plan.md from azure-prepare and validated status from azure-validate. WHEN: "run azd up", "run azd deploy", "execute deployment", "push to production", "push to cloud", "go live", "ship it", "bicep deploy", "terraform apply", "publish to Azure", "launch on Azure". DO NOT USE WHEN: "create and deploy", "build and deploy", "create a new app", "set up infrastructure", "create and deploy to Azure using Terraform" — use azure-prepare for these.
azure-validate
microsoft/azure-skills
Pre-deployment validation for Azure readiness. Run deep checks on configuration, infrastructure (Bicep or Terraform), RBAC role assignments, managed identity permissions, and prerequisites before deploying. WHEN: validate my app, check deployment readiness, run preflight checks, verify configuration, check if ready to deploy, validate azure.yaml, validate Bicep, test before deploying, troubleshoot deployment errors, validate Azure Functions, validate function app, validate serverless deployment, verify RBAC roles, check role assignments, review managed identity permissions, what-if analysis, validate Container Apps deployment.