54·Docker Compose进阶

Compose Profiles

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 的服务总是启动

练习编辑器

bash
Loading...