Skip to content

fix: pre_start hooks receive the service env_file and environment - #14293

Merged
glours merged 2 commits into
docker:mainfrom
ndeloof:investigate-14287-pre-start-env
Oct 12, 2026
Merged

glours merged 2 commits into
docker:mainfrom
ndeloof:investigate-14287-pre-start-env

Conversation

@ndeloof

@ndeloof ndeloof commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

What this PR does, in one sentence

A pre_start hook now runs with the variables coming from the env_file entries it inherits from the service or declares itself.

Context

A hook is a full container specification that inherits the service's attributes and completes them with its own. For environment and env_file that is a merge, not a replacement. In practice the env_file entries were never read for hooks: a service using env_file: .env ran its pre_start command without any of those variables, while docker compose config showed an env_file on the hook and no environment (#14287). Services that carried their variables inline were not affected, which is why this went unnoticed.

What the PR brings

An e2e scenario locking the expected behavior: a hook that declares nothing sees the service's env_file and environment, and a hook that declares its own env_file/environment sees both, its own values winning on conflicts. Each hook asserts the variables it must receive and fails the up otherwise.

The fix itself lives in compose-go (compose-spec/compose-go#938, merged), which resolves hook environments exactly like service ones. Compose needs no code change beyond picking it up: the compose-go dependency is bumped to that commit, which is not part of a release yet.

Fixes #14287

🤖 Generated with Claude Code

@ndeloof
ndeloof requested a review from docker-agent October 7, 2026 06:41

@docker-agent docker-agent left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Assessment: 🔴 CRITICAL

Comment thread go.mod Resolved
@codecov

codecov Bot commented Oct 7, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

…vironment

Reproduces docker#14287: a hook inheriting the service's
env_file (or declaring its own) runs without those variables.

Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
Picks up compose-spec/compose-go#938, which resolves the env_file entries
of pre_start hooks like the service ones.

Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
@ndeloof
ndeloof force-pushed the investigate-14287-pre-start-env branch from 0130978 to 0d300bc Compare October 12, 2026 15:31
@ndeloof
ndeloof requested a review from docker-agent October 12, 2026 15:33

@docker-agent docker-agent left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Assessment: 🟢 APPROVE

@ndeloof
ndeloof marked this pull request as ready for review October 12, 2026 15:47
@ndeloof
ndeloof requested review from a team as code owners October 12, 2026 15:47
@ndeloof
ndeloof requested a review from glours October 12, 2026 15:47

@docker-agent docker-agent left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Assessment: 🟢 APPROVE

@glours glours left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

@glours
glours merged commit 635221b into docker:main Oct 12, 2026
65 of 66 checks passed
tmatens added a commit to tmatens/compose-lint that referenced this pull request Nov 10, 2026
Compose 5.7.0 applies env files to pre_start hooks (docker/compose#14293):
a hook receives its service's env_file values, then its own, and
environment: still wins over every file. ADR-040 §7 had recorded a hook's
env_file as inert on 5.6.1, and its premise check failed on the 5.7.0
bump as planned.

Read a hook's own env_file targets as a service's are, and grade the keys
whose value the hook deploys and its service does not. A value that
reaches the hook unchanged stays the service's finding. The premise check
now expects inert below 5.7 and applied from 5.7, measured on both.

Closes #1220.

Signed-off-by: Todd <tmatens@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants