本文介绍了不同的env-file但是与Docker Compose相同的yml?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我发现我有很多常见的情况,我有多个环境(例如test和prod),但是我希望开始的Docker容器在两个环境中都是一样的。唯一的区别是我想使用 env-file 指定的应用程序配置。由于我有多个容器和依赖关系,我想使用 docker-compose 。但是afaik我只能在 docker-compose.yml 文件中指定一个 env-file (请参阅docs )。如果是这种情况,那么我需要将我原来的 docker-compose.yml 克隆到两个不同的文件(一个用于测试,另一个用于prod)只是指向不同的env文件。这意味着我必须维护两个 docker-compose.yml 文件而不是一个,如果我进行任何更改,我需要更新这两个文件。 这是真的根据设计吗?为什么我不做 docker-compose 让我指定 - env-file 当我做 docker-compise up 或 docker-compose run ?解决方案 请参阅下面的更新#2。这是可能的! 这是Docker Compose的一个非常要求的功能。不幸的是,目前的答案是你不能。我建议订阅这些GitHub问题,以便在实现此功能时更好地了解: https://github.com/docker/compose/issues/495 https://github.com/docker/compose/pull/76 https://github.com/docker/compose/pull/845 问题#495实际上是当前在其问题存储库中最多的评论。你绝对不会孤单想要这样做。 更新: 最新的问题跟踪是 https://github.com/docker/compose/issues/1377 。 更新#2: 此功能已合并,可从Docker Compose 1.5.0开始使用。请参阅 https://github.com/docker/compose/ blob / 129092b7 / docs / yml.md#可变替代的使用信息。 I find it quite common that I have multiple environments (for example test and prod) but the Docker containers that I wish to start are the same in both environments. The only difference is the application configuration which I want to specify using an env-file. Since I have multiple containers and dependencies between them I want to use docker-compose. But afaik I can only specify an env-file inside the docker-compose.yml file (see docs). If this is the case then I need to clone my original docker-compose.yml to two different files (one for test and one for prod) just to point to different env files. This means that I have to maintain two docker-compose.yml files instead of one and if I make any changes I need to update both files.Is this really according to design? Why won't docker-compose let me specify --env-file when I do docker-compose up or docker-compose run? 解决方案 See Update #2 below. This is now possible!This is a much requested feature of Docker Compose. Unfortunately, the answer at the moment is that you can't. I'd recommend subscribing to these GitHub issues to get a better idea when and if this feature gets implemented:https://github.com/docker/compose/issues/495https://github.com/docker/compose/pull/76https://github.com/docker/compose/pull/845Issue #495 is actually the most commented in their issue repository at the moment. You are definitely not alone in wanting to do this.Update:The latest issue tracking is at https://github.com/docker/compose/issues/1377.Update #2:This functionality has been merged and is available as of Docker Compose 1.5.0. See https://github.com/docker/compose/blob/129092b7/docs/yml.md#variable-substitution for usage information. 这篇关于不同的env-file但是与Docker Compose相同的yml?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 07-24 22:36