Different env-file but same yml with Docker Compose?
Answer a question
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?
Answers
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/495
- https://github.com/docker/compose/pull/76
- https://github.com/docker/compose/pull/845
Issue #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.
更多推荐
所有评论(0)