简体   繁体   English

如何从文件读取docker-compose的配置

[英]How to read configuration for a docker-compose from a file

I have a docker-compose file which looks like below 我有一个docker-compose文件,如下所示

services:
  service1:
    image: image_name:image_tag
    container_name: cname

image_tag and cname can change from deployment to deployment, so I want to have a configuration file (in format of key=value) and read the value of image_tag and cname from it. image_tagcname可以随部署而变化,因此我想拥有一个配置文件(格式为key = value),并从中读取image_tagcname的值。 How can I fo that? 我该怎么做?

From the docs: https://docs.docker.com/compose/environment-variables/#the-env-file 从文档中: https : //docs.docker.com/compose/environment-variables/#the-env-file

You can put an .env file near the docker-compose file. 您可以将.env文件放在docker-compose文件附近。 eg: 例如:

.env: .ENV:

image_tag=1.0.0
cname=cname

docker-compose.yml: 泊坞窗,compose.yml:

services:
  service1:
    image: image_name:${image_tag}
    container_name: ${cname}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM