Proposal to change logic for loading env file for the docker-compose (--env-file) #9931
Description
Hello Docker Team
Thank's for the great products Docker and Docker compose.
Currently PHP Symfony framework has next logic for loading .env files:
# In all environments, the following files are loaded if they exist,
# the latter taking precedence over the former:
#
# * .env contains default values for the environment variables needed by the app
# * .env.local uncommitted file with local overrides
# * .env.$APP_ENV committed environment-specific defaults
# * .env.$APP_ENV.local uncommitted environment-specific overrides
# Real environment variables win over .env files.
When using docker-compose, it loads .env file by the default, but we are able to use --env-file option in order to specify path for docker envs variables. If file missing then error provided and we even can't build containers.
Such logic leads to the situation, when we want to override some variables, we need to have a separate .env file for the docker(f.e. docker/.env) and this file should be "uncommitted file". It means, that at the same time, we need to have some .env.example file(docker/.env.example) for the docker that committed. So, after such actions, every time, after pulling new changes from the git, every developer need to check if we have some new envs inside docker/.env.example and copy new values into uncommitted file docker/.env (f.e. some of the team-member has MacOS and he need to change some env variable without committing it).
We have proposal do not have different .env files for the Symfony and docker-compose(.env + docker/.env) if we already have one in the parent folder of the project. We have proposal to ask you to add additional option for the docker-compose, like --env-file-if-exists=... and in such case we can have the same behavior for the symfony framework and docker-compose. So final docker-compose instruction inside Makefile can be like next:
docker-compose --env-file .env --env-file-if-exists .env.local --env-file-if-exists .env.dev --env-file-if-exists .env.dev.local -f docker-compose.yml build
With hope
Thanks in Advance