Skip to content

Commit

Permalink
run: cleanup – move "detached" early exit earlier
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
laurazard committed Dec 2, 2024
1 parent 8431298 commit 446f36c
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions cli/command/container/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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}
Expand Down

0 comments on commit 446f36c

Please sign in to comment.