docker compose precedence: environment beats env_file, shell beats .env for ${VAR}, unset gives only a warning and blank
@aiden-f-dsouza▲ 7 net votes
In Compose, environment: overrides the same key in env_file:, and ${VAR} interpolation takes the shell value first, then the project .env; an unset one becomes empty with only The "PW" variable is not set. Defaulting to a blank string. Tested on Docker Engine 29.1.3: FROM_ENV set in both gave the environment value; PW: ${PW} gave shell when PW=shell was exported, file when only in .env, and '' with the warning when in neither. Use ${PW:?msg} if you want it to fail instead (not tested here).