docker-compose
Docker Compose orchestration for multi-container applications
安装与使用
请根据来源仓库和你的 AI 工具说明安装此技能。先阅读技能文件和依赖要求,再添加到工作流。
查看来源 ↗使用指南技能说明
What I do
- Create docker-compose.yml for service orchestration
- Define multi-stage builds and service dependencies
- Configure volumes, networks, and environment variables
- Set up health checks and restart policies
- Debug container startup and networking issues
- Manage container lifecycle (start, stop, rebuild)
When to use me
Use me when orchestrating multi-container applications, especially when:
- Setting up local development environments
- Configuring production deployments
- Managing service dependencies and networking
- Debugging container communication issues
- Optimizing image sizes and build times
Common commands
-
docker-compose up -d- Start services in detached mode -
docker-compose down- Stop and remove containers -
docker-compose build- Build images -
docker-compose logs -f- Follow logs -
docker-compose exec service sh- Execute command in container -
docker-compose ps- List running containers
Service configuration
services:
app:
build: .
ports:
- "3000:3000"
environment:
- NODE_ENV=production
volumes:
- ./data:/app/data
depends_on:
- db
restart: unless-stopped
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:3000/health"]
interval: 30s
timeout: 10s
retries: 3
Networking patterns
- Create custom networks for service isolation
- Use service names as hostnames (e.g.,
db:5432) - Expose ports only where necessary (internal vs external)
- Configure DNS resolution for service discovery
Volume strategies
- Named volumes for persistent data
- Bind mounts for live code reloading
- Temporary volumes for caches and logs
- Backup named volumes before major changes
Build optimization
- Use multi-stage builds to reduce image size
- Cache dependencies with COPY layers
- Use
.dockerignoreto exclude unnecessary files - Build once, run multiple times (no build in production containers)
Health checks
- Define health checks for critical services
- Use
depends_on: {condition: service_healthy}for ordering - Implement readiness endpoints in applications
- Configure appropriate timeouts and retries
Debugging tips
- Use
docker-compose logs --tail=100 servicefor recent logs - Enter container with
docker-compose exec service sh - Check networking with
docker network inspect - Verify environment variables with
docker-compose config - Use
--no-cacheflag when troubleshooting builds
使用示例
查看来源仓库中的使用示例与配置说明。
查看来源 ↗来源历史
- 收录时间
- 2026-01-20
- 索引更新时间
- 2026-01-26
- Branch
- main
收录与同步日期属于本站记录。源码修改历史请查看来源仓库。
GitHub ↗chat Comments (0)
Sign in to join the discussion and leave a comment.
No comments yet. Be the first to share your thoughts!