是否可以对不同的服务使用不同的.env? [英] Is it possible to use different .env for different services?

查看:60
本文介绍了是否可以对不同的服务使用不同的.env?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的情况是最好有多个.env文件,在docker-compose.yml中每个服务一个文件。有什么方法可以指定要使用的其他文件名吗?

I have a situation where it would be nice to have multiple .env files, one for each service in my docker-compose.yml. Is there any way to specify a different filename to use? Can this be done on the level of individual services?

我尝试使用 env_file 标记,很遗憾,设置变量以在Dockerfile中使用并在运行时使用。另一方面,.env文件将变量设置为在docker-compose.yml中扩展。

I attempted to use the env_file tag, unfortunately, this sets variables for use in Dockerfile and at run-time. The .env file, on the other hand, sets variables to be expanded in docker-compose.yml.

推荐答案

不幸的是,它是无法为 .env 文件指定替代名称。我也希望能够将其交换出去,但是您可以看到在源代码中是直接编码为 .env

Unfortunately, it's not possible to specify an alternative name for the .env file. I've wanted to be able to swap that out too, but you can see in the source code that's it's coded directly to .env.

是您是否有理由要为每个服务拆分替换变量?感觉您应该能够将所有服务的变量放入单个 .env 文件中。

Is there a reason you want to split out substitution variables per service? It feels like you should be able to put the variables for all of your services into a single .env file.

这篇关于是否可以对不同的服务使用不同的.env?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆