Skip to content

Commit

Permalink
Merge pull request #15161 from ulyssessouza/envvars_precedence
Browse files Browse the repository at this point in the history
Add new environment variables precedence matrix
  • Loading branch information
dockertopia authored Aug 16, 2022
2 parents 4002749 + 1026e71 commit 0f78616
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 2 deletions.
8 changes: 6 additions & 2 deletions _data/toc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1448,8 +1448,12 @@ manuals:
title: Uninstall Docker Compose
- path: /compose/gettingstarted/
title: Getting started
- path: /compose/environment-variables/
title: Environment variables in Compose
- sectiontitle: Environment variables
section:
- path: /compose/environment-variables/
title: Overview
- path: /compose/envvars-precedence/
title: Environment variables' precedence
- path: /compose/env-file/
title: Environment file
- path: /compose/profiles/
Expand Down
40 changes: 40 additions & 0 deletions compose/envvars-precedence.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
---
title: Environment variables precedence
description: TODO
keywords: compose, environment, env file
---

<style>
div {
color: RoyalBlue;
}
table {
font-family: monospace;
}
</style>

- Command Line (docker compose run --env <KEY[=VAL]> https://docs.docker.com/engine/reference/commandline/compose_run/#options)
- Compose File (service::environment section: https://docs.docker.com/compose/compose-file/#environment)
- Compose File (service::env_file section file: https://docs.docker.com/compose/compose-file/#env_file)
- Container Image ENV directive (https://docs.docker.com/engine/reference/builder/#env)

When `WHEREAMI` is the variable in case:

| 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 |
|:-------------------------------------:|:-----------------:|:-----------------------------------------------------------------------------------------:|:----------------------------------:|:-----------------------------------------:|:------------------------------------------------:|:------------------------:|
| <div>Dockerfile</div> | OS_Env | WHEREAMI=DotEnv_File | | | | Dockerfile |
| Dockerfile | OS_Env | WHEREAMI=<div>DotEnv_File</div> | | | WHEREAMI | DotEnv_File |
| Dockerfile | <div>OS_Env</div> | WHEREAMI=${WHEREAMI:-DotEnv_File_DefaultValue} | | | WHEREAMI | OS_Env |
| <div>Dockerfile</div> | OS_Env | WHEREAMI=${WHEREAMI:-DotEnv_File_DefaultValue} | | | | Dockerfile |
| Dockerfile | | WHEREAMI=${WHEREAMI:-<div>DotEnv_File_DefaultValue</div>} | | | WHEREAMI | DotEnv_File_DefaultValue |
| Dockerfile | OS_Env | WHEREAMI=${WHEREAMI:-DotEnv_File_DefaultValue} | | | WHEREAMI=<div>Command_Line</div> | Command_Line |
| Dockerfile | <div>OS_Env</div> | WHEREAMI=${WHEREAMI:-DotEnv_File_DefaultValue} | | WHEREAMI | | OS_Env |
| Dockerfile | OS_Env | WHEREAMI=${WHEREAMI:-DotEnv_File_DefaultValue} | | WHEREAMI=<div>Environment_Section</div> | | Environment_Section |
| Dockerfile | OS_Env | WHEREAMI=${WHEREAMI:-DotEnv_File_DefaultValue} | | WHEREAMI=Environment_Section | WHEREAMI=<div>Command_Line</div> | Command_Line |
| Dockerfile | <div>OS_Env</div> | WHEREAMI=${WHEREAMI:-DotEnv_File_DefaultValue} | | WHEREAMI=Environment_Section | WHEREAMI | OS_Env |
| Dockerfile | OS_Env | WHEREAMI=${WHEREAMI:-DotEnv_File_DefaultValue} | | WHEREAMI | WHEREAMI=<div>Command_Line</div> | Command_Line |
| Dockerfile | OS_Env | | WHEREAMI=Env_File | | WHEREAMI=<div>Command_Line</div> | Command_Line |
| Dockerfile | OS_Env | | WHEREAMI=Env_File | WHEREAMI=<div>Environment_Section</div> | | Environment_Section |
| Dockerfile | OS_Env | | WHEREAMI=<div>Env_File</div> | | | Env_File |
| Dockerfile | <div>OS_Env</div> | | | WHEREAMI=${WHEREAMI:-Environment_Section} | | OS_Env |
| Dockerfile | <div>OS_Env</div> | WHEREAMI=${WHEREAMI:-DotEnv_File_DefaultValue} | | WHEREAMI=${WHEREAMI:-Environment_Section} | | OS_Env |

0 comments on commit 0f78616

Please sign in to comment.