Currently, the order in which environment files are loaded is counterintuitive.
The global environment variables override service-specific ones and global variables cannot be used in service-specific env files.
docker compose --file SERVICE_COMPOSE_FILE --file SERVICE_COMPOSE_OVERRIDE_FILE --env-file SERVICE_ENV_FILE --env-file GLOBAL_ENV_FILE config
Proposed Change
Load the global environment file first, then load the service-specific environment file second.
docker compose --file SERVICE_COMPOSE_FILE --file SERVICE_COMPOSE_OVERRIDE_FILE --env-file GLOBAL_ENV_FILE --env-file SERVICE_ENV_FILE config
Reasoning
A global environment file suggests that its values can be referenced within service-specific environment files, just like they can be used in the compose file.
With the current load order, service-specific variables are overridden by global variables.
Current Behavior
Currently, the order in which environment files are loaded is counterintuitive. The global environment variables override service-specific ones and global variables cannot be used in service-specific env files.
docker compose --file SERVICE_COMPOSE_FILE --file SERVICE_COMPOSE_OVERRIDE_FILE --env-file SERVICE_ENV_FILE --env-file GLOBAL_ENV_FILE config
Proposed Change
Load the global environment file first, then load the service-specific environment file second.
docker compose --file SERVICE_COMPOSE_FILE --file SERVICE_COMPOSE_OVERRIDE_FILE --env-file GLOBAL_ENV_FILE --env-file SERVICE_ENV_FILE config
Reasoning
A global environment file suggests that its values can be referenced within service-specific environment files, just like they can be used in the compose file. With the current load order, service-specific variables are overridden by global variables.
Example Use Case
global.env:
DOMAINNAME=domain.tld
service.env:SERVICEDOMAIN=service.${DOMAINNAME}