[英]Variable for docker repository inside docker-compose.yaml
Is there any way to have a variable inside docker-compose.yaml
for docker repository name?有没有办法在
docker-compose.yaml
中为 docker 存储库名称添加一个变量? Or any other way of declaring repository outside of image name?或者在图像名称之外声明存储库的任何其他方式?
I have a few docker containers in AWS ECR repos and docker-compose file contains several declarations like:我在 AWS ECR 存储库中有几个 docker 容器,并且 docker-compose 文件包含几个声明,例如:
image: <account>.dkr.ecr.<region>.amazonaws.com/<image>:latest
and I would like to declare only once <account>.dkr.ecr.<region>.amazonaws.com
to minimize changes required for deployment in other account or moving images to other repository.我只想声明一次
<account>.dkr.ecr.<region>.amazonaws.com
以尽量减少在其他账户中部署或将图像移动到其他存储库所需的更改。
Many thanks in advance!提前谢谢了!
Yes, you can define it in .env
file in the same folder than your docker-compose.yaml是的,您可以在与 docker-compose.yaml 相同的文件夹中的
.env
文件中定义它
.env .env
ACCOUNT=myaccount
REGION=myregion
IMAGE=niceimage
VERSION=latest
docker-compose.yaml docker-compose.yaml
...
image: ${ACCOUNT}.dkr.ecr.${REGION}.amazonaws.com/${IMAGE}:${VERSION}
You don't need to specify env_file =.env unless you need.env variables inside docker.除非您需要 docker 中的 .env 变量,否则您不需要指定 env_file =.env。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.