I have a profile in my Compose file like:
web_prod_db:
<<: *web
command: etc. etc.
env_file:
- .env
- .env.prod-db
profiles:
- myprofile
I want the values in .env.prod-db
to override the (same-named) variables in .env
, but this doesn’t seem to happen – even if I swap the order that the files are specified so .env.prod-db
is specified first.
Is there anything I can do here to ensure the overrides happen as desired?
2
Answers
To override values, you can use this approach: https://docs.docker.com/compose/extends/
You can create your main docker-compose.yml file, and others dockerfiles that will override values that you desired. As an example:
docker-compose.yml
docker-compose.prod.yml
And run the command:
That will run your containers and will override/merge the values from docker-compose.yml with the values defined in docker-compose.prod.yml
Hope this can be usefull
As stated here:
So the variable defined for a second time in
.env.prod-db
takes president over.env