配置 文件
目录
使用配置文件,您可以定义一组活动配置文件,以便针对各种用途和环境调整 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 中。