You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hey! docker compose --env-file=file.env up is ignoring the --env-file option.
Steps To Reproduce
have a docker-compose.yaml file that should use some environment variables from an environment variables file.
example:
version: '3.9'services:
node:
image: node:18container_name: live_dev# it was specifically chosen to hang the container so that we can inspect itcommand: tail -F anything
have an file.env file:
example:
MY_VAR=my_var
have the following directory structure:
[~/live_dev] $ tree -a
.
├── docker-compose.yaml
└── file.env
1 directory, 2 files
run the docker compose --env-file=file.env up
enter the container via docker exec -it live_dev /bin/bash
Adding env_file to the docker-compose.yaml and running docker compose up loads the file and makes the variable present.
version: '3.9'services:
node:
image: node:18env_file:
- file.envcontainer_name: live_dev# it was specifically chosen to hang the container so that we can inspect itcommand: tail -F anything
Did some investigation and it seems it was removed from build, up and down some time ago(maybe in the Python version and got ported to the Go version, I am not sure). #6800 and also has something to do with #10650
I don't know if this is supposed to happen.
The text was updated successfully, but these errors were encountered:
The --env-file command-line argument overrides Compose behavior that automatically looks for a file named .env in the current directory. The .env file (or file at path specified by --env-file) is merged with the system environment to perform variable resolution inside the Compose YAML. That is, this let's you do things like image: ${IMAGE} in your YAML, and then have it substituted by putting IMAGE=alpine in a .env file (or running IMAGE=alpine docker compose ...).
Unfortunately, this is named the same as the env_file YAML field, both of which are taken from Docker CLI's --env-file option, which is confusing, as the YAML field is for passing through to containers, while the CLI flag is for substitution within YAML.
I'm closing this issue, but cc @aevesdocker on our docs team, we improved this recently around precedence, syntax & mechanisms, but we might need an extra call-out for this distinction.
Description
Hey!
docker compose --env-file=file.env up
is ignoring the--env-file
option.Steps To Reproduce
docker-compose.yaml
file that should use some environment variables from an environment variables file.example:
file.env
file:example:
[~/live_dev] $ tree -a . ├── docker-compose.yaml └── file.env 1 directory, 2 files
docker compose --env-file=file.env up
docker exec -it live_dev /bin/bash
printenv
to see ifMY_VAR
existsMY_VAR
doesn't existCompose Version
Docker Environment
Anything else?
Adding
env_file
to thedocker-compose.yaml
and runningdocker compose up
loads the file and makes the variable present.Did some investigation and it seems it was removed from
build
,up
anddown
some time ago(maybe in the Python version and got ported to the Go version, I am not sure). #6800 and also has something to do with #10650I don't know if this is supposed to happen.
The text was updated successfully, but these errors were encountered: