-
Notifications
You must be signed in to change notification settings - Fork 5.8k
[BUG] short and long form includes ignore .env files #10913
Description
Description
The new include spec says:
Short Syntax:
Variables are interpolated using values set in the optional .env file in same folder, and is overridden by the local project's environment.
Long Syntax:
env_file defines an environment file(s) to use to define default values when interpolating variables in the Compose file being parsed. It defaults to .env file in the project_directory for the Compose file being parsed.
...
The local project's environment has precedence over the values set by the Compose file, so that the local project can override values for customization.
However, docker-compose seems to completely ignore both implicit and explicit .env files in includes.
Steps To Reproduce
-
Create a directory called "postgres" that includes the following files:
.env:POSTGRES_USER=postgres POSTGRES_PASSWORD=password POSTGRES_PORT=6432postgres.yml:services: postgresql: container_name: postgresql environment: POSTGRES_USER: ${POSTGRES_USER} POSTGRES_PASSWORD: ${POSTGRES_PASSWORD} PGPORT: ${POSTGRES_PORT} image: postgres:14 ports: - ${POSTGRES_PORT}:${POSTGRES_PORT}
-
Create a directory called "test" (alongside "postgres") with the following file:
test.yml:include: - ../postgres/postgres.yml
OR
include: - path: ../postgres/postgres.yml project_directory: ../postgres env_file: ../postgres/.env
-
From a CLI, cd into the
postgresdirectory and run:docker-compose -f .\postgres.yml config- docker-compose will output valid config with no warnings and the three env variables specified in the.envfile filled in throughout the config. -
From a CLI, cd into the
testdirectory and run:docker-compose -f .\test.yml config- docker-compose will warn that it can't find any of the variables defined in the postgres.envfile:
time="2023-08-18T17:08:08-07:00" level=warning msg="The \"POSTGRES_USER\" variable is not set. Defaulting to a blank string."
time="2023-08-18T17:08:08-07:00" level=warning msg="The \"POSTGRES_PASSWORD\" variable is not set. Defaulting to a blank string."
time="2023-08-18T17:08:08-07:00" level=warning msg="The \"POSTGRES_PORT\" variable is not set. Defaulting to a blank string."
time="2023-08-18T17:08:08-07:00" level=warning msg="The \"POSTGRES_PORT\" variable is not set. Defaulting to a blank string."
time="2023-08-18T17:08:08-07:00" level=warning msg="The \"POSTGRES_PORT\" variable is not set. Defaulting to a blank string."
1 error(s) decoding:
* error decoding 'ports': No port specified: :<empty>
Compose Version
Docker Compose version v2.20.2-desktop.1
Docker Environment
No response
Anything else?
No response