run: cleanup – move "detached" early exit earlier

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 <laurabrehm@hey.com>
This commit is contained in:
Laura Brehm 2024-12-02 10:16:12 +00:00
parent 8431298824
commit 446f36ce58
No known key found for this signature in database
GPG Key ID: 08EC1B0491948487

View File

@ -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}