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}