Recently I have encountered an issue with docker compose
. I have separated the environment files and declared todocker-compose.yaml
like following,
env_file:
- .dev_env
When I ran docker compose up
, it was not working on the compose itself but the container. because of environment variables. Then I found following solution for this.
docker compose --env-file .dev_env --env-file .prod_env up
Top comments (2)
We have been using this in
docker 24.0.2
Even it can process multiple files, where one
key
declared in one file can be overridden by the declaration of the samekey
in later file(s)Moreover docker prioritise taking value from the host environment first. If it's not declared then, it's tried to resolved from the
.env
file or the file provided specified.After all fail attempt to retrieve the value it uses the default value given after the
:-
in thedocker-compose.yml
file.Thank you for your point. But in my case I was using the env variables on the compose file itself. like following,