Skip to content

Commit 1026e71

Browse files
committed
Add new environment variables precedence matrix
Signed-off-by: Ulysses Souza <[email protected]>
1 parent 08184fc commit 1026e71

2 files changed

Lines changed: 46 additions & 2 deletions

File tree

_data/toc.yaml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1413,8 +1413,12 @@ manuals:
14131413
title: Uninstall Docker Compose
14141414
- path: /compose/gettingstarted/
14151415
title: Getting started
1416-
- path: /compose/environment-variables/
1417-
title: Environment variables in Compose
1416+
- sectiontitle: Environment variables
1417+
section:
1418+
- path: /compose/environment-variables/
1419+
title: Overview
1420+
- path: /compose/envvars-precedence/
1421+
title: Environment variables' precedence
14181422
- path: /compose/env-file/
14191423
title: Environment file
14201424
- path: /compose/profiles/

compose/envvars-precedence.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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

Comments
 (0)