mirror of https://github.com/docker/docs.git
Clarify order for overriding env vars
This commit is contained in:
parent
d670e54ac3
commit
f3804e6012
|
@ -126,10 +126,16 @@ services:
|
||||||
image: 'webapp:v2.0'
|
image: 'webapp:v2.0'
|
||||||
```
|
```
|
||||||
|
|
||||||
When values are provided both with a shell `environment` variable and with an
|
When you set the same environment variable in multiple files, here's the
|
||||||
`env_file` configuration file, values of environment variables is taken
|
priority used by Compose to choose which value to use:
|
||||||
from environment key first and then from environment file, then from a
|
|
||||||
`Dockerfile` `ENV`–entry:
|
1. Compose file,
|
||||||
|
2. Environment file,
|
||||||
|
3. Dockerfile,
|
||||||
|
4. Variable is not defined.
|
||||||
|
|
||||||
|
In the example below, we set the same environment variable on an Environment
|
||||||
|
file, and the Compose file:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
$ cat ./Docker/api/api.env
|
$ cat ./Docker/api/api.env
|
||||||
|
@ -146,8 +152,8 @@ services:
|
||||||
- NODE_ENV=production
|
- NODE_ENV=production
|
||||||
```
|
```
|
||||||
|
|
||||||
You can test this with a command like the following command that starts a
|
When you run the container, the environment variable defined in the Compose
|
||||||
_NodeJS_ container in the CLI:
|
file takes precedence.
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
$ docker-compose exec api node
|
$ docker-compose exec api node
|
||||||
|
|
Loading…
Reference in New Issue