配置 文件
目录
使用配置文件,您可以定义一组活动配置文件,以便针对各种用途和环境调整 Compose 应用程序模型。
services 顶级元素支持profiles属性来定义命名用户档案的列表。
没有profiles属性始终处于启用状态。
当列出的profiles匹配活动 Ones ,除非服务
由命令显式定位。在这种情况下,其配置文件将添加到活动配置文件集中。
注意
所有其他顶级元素不受
profiles并始终处于活动状态。
对其他服务的引用(通过links,extends或共享资源语法service:xxx) 不要
自动启用原本会被活动配置文件忽略的组件。相反
Compose 返回错误。
说明示例
services:
web:
image: web_image
test_lib:
image: test_lib_image
profiles:
- test
coverage_lib:
image: coverage_lib_image
depends_on:
- test_lib
profiles:
- test
debug_lib:
image: debug_lib_image
depends_on:
- test_lib
profiles:
- debug在上面的示例中:
- 如果在未启用配置文件的情况下解析 Compose 应用程序模型,则它仅包含
web服务。 - 如果配置文件
test启用时,模型包含服务test_lib和coverage_lib和 serviceweb,该模块始终处于启用状态。 - 如果配置文件
debug启用时,模型将同时包含web和debug_lib服务,但不是test_lib和coverage_lib, 因此,该模型对depends_on的约束debug_lib. - 如果配置文件
debug和test启用,则模型包含所有服务;web,test_lib,coverage_lib和debug_lib. - 如果 Compose 是使用
test_lib作为要运行的显式服务,test_lib和test轮廓 即使test配置文件未启用。 - 如果 Compose 是使用
coverage_lib作为要运行的显式服务,则 Servicecoverage_lib和 轮廓test处于活动状态且test_lib被depends_on约束。 - 如果 Compose 是使用
debug_lib作为要运行的显式服务,模型同样是 invalid(对depends_on的约束debug_lib因为debug_lib和test_lib没有普通profiles上市。 - 如果 Compose 是使用
debug_lib作为显式服务来运行和分析test已启用, 轮廓debug已自动启用,并且服务test_lib作为依赖项拉取,同时启动 服务业debug_lib和test_lib.
了解如何使用profiles在 Docker Compose 中。