Compose Profiles
核心概念
services:
app:
image: my-app
# 无 profile,总是启动
debug-tools:
image: busybox
profiles:
- debug # 只在 debug profile 启动
monitoring:
image: prometheus
profiles:
- monitoring
使用
# 只启动默认服务
docker compose up
# 启动 debug 相关服务
docker compose --profile debug up
# 启动多个 profile
docker compose --profile debug --profile monitoring up
使用场景
- 开发工具(debug profile)
- 监控服务(monitoring profile)
- 测试服务(test profile)
小结
| 语法 | 说明 |
|---|---|
profiles: | 服务分组 |
--profile | 启用指定 profile |
| 无 profile 的服务 | 总是启动 |