Skip to content

fix(dry-run): skip lifecycle hooks instead of failing on exec attach - #14504

Merged
glours merged 3 commits into
docker:mainfrom
glours:fix-dry-run-hooks
Nov 16, 2026
Merged

glours merged 3 commits into
docker:mainfrom
glours:fix-dry-run-hooks

Conversation

@glours

@glours glours commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Under --dry-run, any lifecycle hook (pre_stop on down/stop/restart, post_start on up/restart) made the command fail with interactive exec is not supported in dry-run mode: the dry-run client creates the exec but cannot attach to it.

runHook now returns early in dry-run mode. Hooks are skipped, since a dry-run must have no side effects, and this single guard covers the hook phases of up, down, stop and restart.

compose --dry-run run on a service with a post_start hook still hangs, as it does on main. It never reaches runHook, so it is left for a follow-up.

The dry-run client cannot attach to an exec, so any lifecycle hook
reached under --dry-run (pre_stop on down/stop/restart, post_start on
up/restart) made the command fail with "interactive exec is not
supported in dry-run mode".

A dry-run must have no side effects, so skip the hook in runHook, which
every hook phase goes through, rather than guarding each call site.

Signed-off-by: Guillaume Lours <glours@users.noreply.github.com>
@glours
glours requested review from a team as code owners November 13, 2026 18:07
@glours
glours requested a review from ndeloof November 13, 2026 18:07
@glours glours changed the title fix(dry-run): skip lifecycle hooks instead of failing fix(dry-run): skip lifecycle hooks instead of failing on exec attach Nov 13, 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

@codecov

codecov Bot commented Nov 13, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@ndeloof ndeloof 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. Two small points, neither blocking:

  • The description says the single guard covers every hook phase, but compose --dry-run run on a service with a post_start hook never reaches it: it hangs forever (same on main). runPostStartHooksOnEvent waits for a start event that the dry-run client never produces, and run.go then waits on hookErrCh after RunStart fails. Out of scope here, but worth a follow-up.
  • nit: see the inline comment.

Comment thread pkg/compose/hook.go
// A dry-run must have no side effects, and the dry-run client cannot
// attach to an exec: skip the hook rather than fail on it.
if s.dryRun {
return nil

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.

nit: a logrus.Debugf here would make the skip discoverable with --verbose (logrus isn't imported in hook.go yet).

ndeloof
ndeloof previously approved these changes Nov 14, 2026
WithDryRun re-initializes the Docker CLI with fresh client options,
whose empty log level makes Initialize reset logrus to info. Under
--dry-run, --verbose was therefore dropped as soon as the backend was
created, hiding every debug log of the operation.

Signed-off-by: Guillaume Lours <glours@users.noreply.github.com>
Hooks are skipped silently under --dry-run. Log each skipped hook at
debug level so --verbose shows which one would have run.

Signed-off-by: Guillaume Lours <glours@users.noreply.github.com>

@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

This incremental review covers only the commits pushed since ab56ce19494c.

The two changes in this incremental diff are correct:

  1. pkg/compose/compose.go — Preserving the current logrus level before cli.Initialize in WithDryRun by assigning options.LogLevel = logrus.GetLevel().String(). logrus.GetLevel() uses an atomic load (no race), the logrus import was already present, and this correctly prevents Initialize from resetting a non-default log level (e.g. set by --verbose) to info.

  2. pkg/compose/hook.go — Adding a logrus.Debugf call before the existing return nil in the if s.dryRun guard gives useful diagnostics when hooks are skipped. The logrus import added for this is correctly ordered (third-party block). One minor note: %v on hook.Command ([]string) produces bracket-delimited unquoted output ([cmd arg]) that becomes ambiguous when arguments contain spaces; %q would produce unambiguous output — but this is debug-level only with no functional impact, so no inline comment is warranted.

@glours
glours merged commit 7b52f3c into docker:main Nov 16, 2026
63 checks passed
@glours
glours deleted the fix-dry-run-hooks branch November 16, 2026 13:34
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.

3 participants