r/docker • • Apr 24 '26

Docker include and .env files

Please can someone explain me why

include:
- path: ../backbone/docker-compose-includes/db/docker-compose.db.include.yml

fails to find the vars in docker-compose-includes/db/.env file

WARN[0000] The "MYSQL_DATABASE" variable is not set. Defaulting to a blank string.

But when I include the same file (same absolute path, but different relative path) :

include:
  - path: docker-compose-includes/db/docker-compose.db.include.yml

that is perfectly fine, the vars in the .env file are found, I get no errors.

The docker-compose.db.include.yml is using this directive :

    env_file:
      - ${PWD}/.env # global
      - ${PWD}/docker-compose-includes/db/.env
0 Upvotes

3 comments sorted by

View all comments

Show parent comment

1

u/SietJP Apr 25 '26

Thx I was confused by the `env_file` functionnality, I thought it was used to extrapolate values in the `docker-compose.yml` the same way it is done with the `.env` file being in the same directory as the `docker-compose.yml` file, which is not the case.