From 0eb87bdd19acde8ddfe9fb560c53b8af3d32a65f Mon Sep 17 00:00:00 2001 From: vigneshakaviki Date: Sun, 14 Jun 2026 22:29:10 -0700 Subject: [PATCH] fix: flush stderr before printing hooks to ensure correct output order When a command fails and error-hooks are enabled, the hooks were being printed before the command's error message appeared in the output, creating confusing output like: What's next: ... docker: open ./no-such-file: no such file or directory This fix ensures stderr is flushed before printing hooks, so error messages appear in the correct order: docker: open ./no-such-file: no such file or directory What's next: ... Fixes: docker/cli#6973 Signed-off-by: vigneshakaviki --- cmd/docker/docker.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/cmd/docker/docker.go b/cmd/docker/docker.go index 0efcc70118fe..c848c61f2d98 100644 --- a/cmd/docker/docker.go +++ b/cmd/docker/docker.go @@ -546,6 +546,10 @@ func runDocker(ctx context.Context, dockerCli *command.DockerCli) error { // If the command is being executed in an interactive terminal // and hook are enabled, run the plugin hooks. if subCommand != nil && dockerCli.Out().IsTerminal() && dockerCli.HooksEnabled() { + // Ensure stderr is flushed before printing hooks so error messages appear first + if errs, ok := dockerCli.Err().(*os.File); ok { + _ = errs.Sync() + } pluginmanager.RunCLICommandHooks(ctx, dockerCli, cmd, subCommand, cmdErrorMessage(err)) }