该
extends选项可能是好的,但它不支持在
3.x撰写文件。其他走的方式是:
- 扩展名字段(撰写文件3.4+)
如果可以使用3.4+组成文件,则扩展名字段可能是最佳选择:
docker-compose.yml
version: '3.4'x-common-variables: &common-variables VARIABLE: some_value ANOTHER_VARIABLE: another_valueservices: some_service: image: someimage environment: *common-variables another_service: image: anotherimage environment: <<: *common-variables NON_COMMON_VARIABLE: 'non_common_value'
- env_file指令
docker-compose.yml
version: '3.2'services: some_service: image: someimage env_file: - 'variables.env' another_service: image: anotherimage env_file: - 'variables.env'
variables.env
VARIABLE=some_valueANOTHER_VARIABLE=another_value
- * 项目根目录中的 *.env 文件(或实际撰写环境中的变量)
.env文件中的变量可以在服务配置中引用:
docker-compose.yml
version: '3.2'services: some_service: image: someimage environment: - VARIABLE another_service: image: anotherimage environment: - VARIABLE - ANOTHER_VARIABLE
.env
VARIABLE=some_valueANOTHER_VARIABLE=another_value
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)