Loading...
Loading...
Compare original and translation side by side
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
| services | array | No | - | List of services to configure |
| environment | enum | No | dev | dev/staging/prod |
| include_monitoring | boolean | No | false | Add monitoring services |
| 参数 | 类型 | 是否必填 | 默认值 | 描述 |
|---|---|---|---|---|
| services | 数组 | 否 | - | 要配置的服务列表 |
| environment | 枚举 | 否 | dev | 开发/预发布/生产 |
| include_monitoring | 布尔值 | 否 | false | 添加监控服务 |
versionservices:services:
frontend:
build:
context: ./frontend
target: production
ports:
- "80:80"
depends_on:
backend:
condition: service_healthy
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost/health"]
interval: 30s
timeout: 10s
retries: 3
restart: unless-stopped
backend:
build: ./backend
expose:
- "3000"
environment:
DATABASE_URL: postgres://user:${DB_PASSWORD}@database:5432/app
depends_on:
database:
condition: service_healthy
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:3000/health"]
interval: 10s
timeout: 5s
retries: 5
database:
image: postgres:16-alpine
volumes:
- db_data:/var/lib/postgresql/data
environment:
POSTGRES_PASSWORD: ${DB_PASSWORD}
healthcheck:
test: ["CMD-SHELL", "pg_isready -U postgres"]
interval: 5s
timeout: 5s
retries: 5
volumes:
db_data:versionservices:services:
frontend:
build:
context: ./frontend
target: production
ports:
- "80:80"
depends_on:
backend:
condition: service_healthy
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost/health"]
interval: 30s
timeout: 10s
retries: 3
restart: unless-stopped
backend:
build: ./backend
expose:
- "3000"
environment:
DATABASE_URL: postgres://user:${DB_PASSWORD}@database:5432/app
depends_on:
database:
condition: service_healthy
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:3000/health"]
interval: 10s
timeout: 5s
retries: 5
database:
image: postgres:16-alpine
volumes:
- db_data:/var/lib/postgresql/data
environment:
POSTGRES_PASSWORD: ${DB_PASSWORD}
healthcheck:
test: ["CMD-SHELL", "pg_isready -U postgres"]
interval: 5s
timeout: 5s
retries: 5
volumes:
db_data:undefinedundefined
```bash
```bashundefinedundefinedundefinedundefined
```yaml
```yamlundefinedundefinedservices:
app:
image: myapp
# Only with --profile debug
debugger:
image: debug-tools
profiles:
- debug
# Only with --profile testing
test-db:
image: postgres:alpine
profiles:
- testingdocker compose up # app only
docker compose --profile debug up # app + debuggerservices:
app:
image: myapp
# 仅在--profile debug模式下启动
debugger:
image: debug-tools
profiles:
- debug
# 仅在--profile testing模式下启动
test-db:
image: postgres:alpine
profiles:
- testingdocker compose up # 仅启动app
docker compose --profile debug up # 启动app + debuggerundefinedundefinedundefinedundefined| Error | Cause | Solution |
|---|---|---|
| Dependency missing | Define service |
| Indentation | Fix YAML |
| Port conflict | Change port |
| Service not ready | Increase start_period |
| 错误 | 原因 | 解决方案 |
|---|---|---|
| 依赖缺失 | 定义对应的服务 |
| 缩进错误 | 修复YAML格式 |
| 端口冲突 | 修改端口 |
| 服务未就绪 | 增加start_period时长 |
docker compose config--no-depsdocker compose config--no-depsdocker compose configdocker compose pulldocker compose configdocker compose pullundefinedundefinedundefinedundefinedSkill("docker-compose-setup")Skill("docker-compose-setup")