I know that docker compose can read environment variables into itself by reading .env
file that must reside in the same directory where the docker-compose
file is located. Usually this is the root of the project.
I want to keep ALL my environment files in a specific dedicated directory called envs
.
So I have this setup:
\project_root:
\envs
.compose_envs.yml
.django_envs.yml
main.py
docker-compose.yml
Is there a directive for docker compose to read environment variables from this custom location?
PS: I know I can do something like this:
set -a; source /path/to/your/env/file; set +a; docker-compose up -d
but I would like to use a docker compose directive and run the container just with docker compose up
PPS: this question is not about -env_file
directive, since this one populates the container with the specified variables, but I want to reference environment variables in the docker-compose
itself, for example in this section:
environment:
POSTGRES_DB: ${POSTGRES_DB}
Some good solutions here:
How can I use environment variables in docker-compose?
but still nothing about my use case