Skip to content

Conversation

@MaheshThakur9152
Copy link

@MaheshThakur9152 MaheshThakur9152 commented Jan 22, 2026

Problem
When a top-level include supplies variables via env_file, those variables were not available later when parsing env_file referenced by services in the included compose file. Repro:

# compose.yml
include:
  - path: subproj/subcompose.yml
    env_file:
      - values.env

# subproj/subcompose.yml
services:
  app:
    env_file: subvalues.env
    image: helloworld

# subproj/subvalues.env
MYVAR=${VAR?}

# values.env
VAR=1

docker compose config failed with: required variable VAR is missing a value.

Fix
Merge variables read from an include's env_file into the parent environment so they are available when service-level env_file files are parsed later during project resolution. This is a small, non-invasive change in include.go.

Files changed

  • include.go — merge include env_file vars into parent environment 🔁
  • include_test.go — added TestIncludeEnvFileInterpolation (regression test) ✅

Tests

  • Added unit test TestIncludeEnvFileInterpolation in loader package.
  • Please verify locally or rely on CI:
    • go test ./loader -run TestIncludeEnvFileInterpolation -v
    • go test mahesh.

Compatibility & scope

  • No public API changes. Behavior is more consistent with expectation that include-provided variables are usable by included files’ env_files.
  • Minimal change consistent with existing loader architecture.

Suggested commit message

loader: merge include env_file vars so subproject env_file interpolation works

- Merge env vars read from include.env_file into parent env so service env_files
  inside included compose files can interpolate those variables.
- Add TestIncludeEnvFileInterpolation to cover regression.

Checklist for reviewers

  • Confirm unit tests pass in CI (go test mahesh.)
  • Validate tests cover the reported repro & edge-case precedence
  • Confirm change is minimally invasive and well documented in PR/changelog

Related issue

return err
}

// Make env vars from the include's env_file available to the parent
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

parent MUST not get those variables, they only SHOULD apply to included compose file. parent project to declare the same variable SHOULD not get value resolved

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants