compose: Inconsistent behavior between `--env-file` CLI flag and `env_file` YAML field
step to reproduce
- clone this repo https://github.com/Legion112/docker-compose-env-file
- run
VARIABLE_FROM_DOT_ENV_DOCKER=somevalue docker compose run --rm app
You would see WARNING like : WARN[0000] The "VARIABLE_FROM_DOT_ENV" variable is not set. Defaulting to a blank string.
How to remove that warning:
- run
VARIABLE_FROM_DOT_ENV_DOCKER=somevalue docker compose --env-file .env.docker run --rm app
Now imaging that you have a ‘Makefile’ like
doctrine.reload:
@docker-compose exec app php bin/console --env=test doctrine:database:drop --if-exists --force
@docker-compose exec app php bin/console --env=test doctrine:database:create --if-not-exists
@docker-compose exec app php bin/console --env=test doctrine:migrations:migrate --no-interaction
@docker-compose exec app php bin/console --env=test doctrine:fixtures:load --append
In every call of docker-compose exec
you have to pass --env-file
otherwise you would see those annoying warning.
Would be nice to not pass --env-file
on every CLI call.
About this issue
- Original URL
- State: closed
- Created a year ago
- Comments: 21 (5 by maintainers)
@hahattan you can but then path resolution in your compose file will be affected. Better use
--env-file .env
to explicitly load this env file and keep parsing use paths relative to first compose file@Legion112 Ok I got it, sorry, I’ll check why we don’t have the same behaviour between the usage of the
--env-file
flag and theenv_file
attribute