Skip to content

fix(cli): load the project from COMPOSE_FILE when -p is set - #14540

Open
glours wants to merge 2 commits into
docker:mainfrom
glours:fix-14535-compose-file-with-project-name
Open

glours wants to merge 2 commits into
docker:mainfrom
glours:fix-14535-compose-file-with-project-name

Conversation

@glours

@glours glours commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #14535

  • COMPOSE_FILE is now handled like -f when -p is set: the model is loaded, so stop runs pre_stop hooks instead of rebuilding a label-only project that doesn't carry them.
  • When the model fails to load, an explicit -p now takes precedence over COMPOSE_PROJECT_NAME in the label-driven fallback (previously the env var won, and commands targeted the wrong project).

projectOrName only loaded the Compose model when -f was passed or when
no project name was given. With -p and COMPOSE_FILE, the model was
skipped, so commands like stop received no project and rebuilt it from
container labels, which don't carry pre_stop hooks: the hooks were
silently not run.

COMPOSE_FILE is the environment equivalent of -f, so treat it the same
way when deciding to load the model.

Fixes docker#14535

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Signed-off-by: Guillaume Lours <glours@users.noreply.github.com>
@glours
glours requested review from a team as code owners November 20, 2026 14:45
@glours
glours requested a review from ndeloof November 20, 2026 14:45
@glours glours changed the title Fix 14535 compose file with project name fix(cli): load the project from COMPOSE_FILE when -p is set Nov 20, 2026

@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

…ilure

When the Compose model can't be loaded, projectOrName falls back to the
label-driven project and used COMPOSE_PROJECT_NAME while ignoring an
explicit -p. With -p x and COMPOSE_PROJECT_NAME=y, commands such as ps,
down or rm then targeted project y instead of x.

Use -p first and COMPOSE_PROJECT_NAME only when -p is empty, matching
the usual precedence.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Signed-off-by: Guillaume Lours <glours@users.noreply.github.com>
@glours
glours force-pushed the fix-14535-compose-file-with-project-name branch from 7d54ab6 to e5a989e Compare November 20, 2026 15:03
@glours
glours requested a review from docker-agent November 20, 2026 15:03

@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: 🟡 NEEDS ATTENTION

Comment thread cmd/compose/compose.go Resolved
@codecov

codecov Bot commented Nov 20, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

This branch has not been deployed

No deployments
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.

[BUG] docker compose stop ignores COMPOSE_FILE when -p is used, skipping pre_stop hooks

2 participants