From 446f36ce58c2c67dd727e8ec7963218e85a36ed5 Mon Sep 17 00:00:00 2001 From: Laura Brehm Date: Mon, 2 Dec 2024 10:16:12 +0000 Subject: [PATCH] =?UTF-8?q?run:=20cleanup=20=E2=80=93=20move=20"detached"?= =?UTF-8?q?=20early=20exit=20earlier?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Since everything else after the `apiClient.ContainerStart` block is under an `if attach` conditional, we can move the "detached" early exit up. Signed-off-by: Laura Brehm --- cli/command/container/run.go | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/cli/command/container/run.go b/cli/command/container/run.go index e122f3c476ab..83f737c9e0af 100644 --- a/cli/command/container/run.go +++ b/cli/command/container/run.go @@ -215,7 +215,14 @@ func runContainer(ctx context.Context, dockerCli command.Cli, runOpts *runOption return toStatusError(err) } - if attach && config.Tty && dockerCli.Out().IsTerminal() { + // Detached mode: wait for the id to be displayed and return. + if !attach { + // Detached mode + <-waitDisplayID + return nil + } + + if config.Tty && dockerCli.Out().IsTerminal() { if err := MonitorTtySize(ctx, dockerCli, containerID, false); err != nil { _, _ = fmt.Fprintln(stderr, "Error monitoring TTY size:", err) } @@ -233,13 +240,6 @@ func runContainer(ctx context.Context, dockerCli command.Cli, runOpts *runOption } } - // Detached mode: wait for the id to be displayed and return. - if !attach { - // Detached mode - <-waitDisplayID - return nil - } - status := <-statusChan if status != 0 { return cli.StatusError{StatusCode: status}