Skip to content

Commit 962b3e1

Browse files
doc on env var precedence wrt config
1 parent 9115c64 commit 962b3e1

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

docs/concepts/configuration.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,20 @@ In the example above, if we assume the value of the configuration variable ***US
6666
6767
During `defang compose up` all variable references will be replaced with the actual value and made available in the container. If any referenced variable is not found the `defang compose up` command will be canceled.
6868
69+
## Environment Variable Precedence
70+
71+
During a deployment, config vars are exposed to your services as environment variables. Environment variables can be set in multiple places, but Defang uses the following precedence order to determine which value to use:
72+
73+
:::note
74+
Defang does pass environment variables from the shell into your services. Environment variables must be set in one of the other supported ways listed below.
75+
:::
76+
77+
1. **Dotenv files**: The `.env` file in the current directory is read by default. This can be overriden per services by specifying the `env_file` service property the `compose.yaml` file.
78+
2. **Docker Compose environment variables**: These are environment variables defined in the `environment` section of the service in the `compose.yaml` file.
79+
3. **Defang config**: These are sensitive configuration values set using the `defang config set FOO=bar` command.
80+
81+
Environment variables are resolved in order of precedence, with the highest precedence value taking priority. For example, if you have a variable `DATABASE_URL` set in both a dotenv file and in Defang config, the value from Defang config will be used.
82+
6983
## Using Config with Pulumi
7084
In Defang, using config with [Pulumi](./pulumi.md) gives you the advantage of being able to manage your environment variables across different environments using Pulumi stacks.
7185

0 commit comments

Comments
 (0)