|
| 1 | +--- |
| 2 | +title: Environment variables precedence |
| 3 | +description: TODO |
| 4 | +keywords: compose, environment, env file |
| 5 | +--- |
| 6 | + |
| 7 | +<style> |
| 8 | +div { |
| 9 | + color: RoyalBlue; |
| 10 | +} |
| 11 | +table { |
| 12 | + font-family: monospace; |
| 13 | +} |
| 14 | +</style> |
| 15 | + |
| 16 | +- Command Line (docker compose run --env <KEY[=VAL]> https://docs.docker.com/engine/reference/commandline/compose_run/#options) |
| 17 | +- Compose File (service::environment section: https://docs.docker.com/compose/compose-file/#environment) |
| 18 | +- Compose File (service::env_file section file: https://docs.docker.com/compose/compose-file/#env_file) |
| 19 | +- Container Image ENV directive (https://docs.docker.com/engine/reference/builder/#env) |
| 20 | + |
| 21 | +When `WHEREAMI` is the variable in case: |
| 22 | + |
| 23 | +| Image (`ENV` directive in Dockerfile) | OS Environment | `.env` file on the project root (or overwrite through `docker compose -–env-file <FILE>`) | Compose file (`service::env_file`) | Compose file (`service::environment`) | Command line (docker compose run -e <KEY[=VAL]>) | RESULT | |
| 24 | +|:-------------------------------------:|:-----------------:|:-----------------------------------------------------------------------------------------:|:----------------------------------:|:-----------------------------------------:|:------------------------------------------------:|:------------------------:| |
| 25 | +| <div>Dockerfile</div> | OS_Env | WHEREAMI=DotEnv_File | | | | Dockerfile | |
| 26 | +| Dockerfile | OS_Env | WHEREAMI=<div>DotEnv_File</div> | | | WHEREAMI | DotEnv_File | |
| 27 | +| Dockerfile | <div>OS_Env</div> | WHEREAMI=${WHEREAMI:-DotEnv_File_DefaultValue} | | | WHEREAMI | OS_Env | |
| 28 | +| <div>Dockerfile</div> | OS_Env | WHEREAMI=${WHEREAMI:-DotEnv_File_DefaultValue} | | | | Dockerfile | |
| 29 | +| Dockerfile | | WHEREAMI=${WHEREAMI:-<div>DotEnv_File_DefaultValue</div>} | | | WHEREAMI | DotEnv_File_DefaultValue | |
| 30 | +| Dockerfile | OS_Env | WHEREAMI=${WHEREAMI:-DotEnv_File_DefaultValue} | | | WHEREAMI=<div>Command_Line</div> | Command_Line | |
| 31 | +| Dockerfile | <div>OS_Env</div> | WHEREAMI=${WHEREAMI:-DotEnv_File_DefaultValue} | | WHEREAMI | | OS_Env | |
| 32 | +| Dockerfile | OS_Env | WHEREAMI=${WHEREAMI:-DotEnv_File_DefaultValue} | | WHEREAMI=<div>Environment_Section</div> | | Environment_Section | |
| 33 | +| Dockerfile | OS_Env | WHEREAMI=${WHEREAMI:-DotEnv_File_DefaultValue} | | WHEREAMI=Environment_Section | WHEREAMI=<div>Command_Line</div> | Command_Line | |
| 34 | +| Dockerfile | <div>OS_Env</div> | WHEREAMI=${WHEREAMI:-DotEnv_File_DefaultValue} | | WHEREAMI=Environment_Section | WHEREAMI | OS_Env | |
| 35 | +| Dockerfile | OS_Env | WHEREAMI=${WHEREAMI:-DotEnv_File_DefaultValue} | | WHEREAMI | WHEREAMI=<div>Command_Line</div> | Command_Line | |
| 36 | +| Dockerfile | OS_Env | | WHEREAMI=Env_File | | WHEREAMI=<div>Command_Line</div> | Command_Line | |
| 37 | +| Dockerfile | OS_Env | | WHEREAMI=Env_File | WHEREAMI=<div>Environment_Section</div> | | Environment_Section | |
| 38 | +| Dockerfile | OS_Env | | WHEREAMI=<div>Env_File</div> | | | Env_File | |
| 39 | +| Dockerfile | <div>OS_Env</div> | | | WHEREAMI=${WHEREAMI:-Environment_Section} | | OS_Env | |
| 40 | +| Dockerfile | <div>OS_Env</div> | WHEREAMI=${WHEREAMI:-DotEnv_File_DefaultValue} | | WHEREAMI=${WHEREAMI:-Environment_Section} | | OS_Env | |
0 commit comments