Skip to content

Commit 1e06654

Browse files
committed
cli: run: avoid wait-for-exit path if running detached
The wait code can output log messages, which can end up with you seeing "errors" due to not being able to get the exit code, when in reality the context is timing our or being cancelled. I'm not sure how common this is on x86, but I can see it all the time on arm64 -- and these error messages seem quite noisy to me (they also cause the integration-cli tests to become quite flaky in my testing). Signed-off-by: Aleksa Sarai <asarai@suse.de>
1 parent 81ac432 commit 1e06654

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

cli/command/container/run.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,11 @@ func runContainer(dockerCli command.Cli, opts *runOptions, copts *containerOptio
166166
defer close()
167167
}
168168

169-
statusChan := waitExitOrRemoved(ctx, dockerCli, createResponse.ID, copts.autoRemove)
169+
// We don't need to wait if we're not attaching.
170+
var statusChan <-chan int
171+
if attach {
172+
statusChan = waitExitOrRemoved(ctx, dockerCli, createResponse.ID, copts.autoRemove)
173+
}
170174

171175
//start the container
172176
if err := client.ContainerStart(ctx, createResponse.ID, types.ContainerStartOptions{}); err != nil {
@@ -186,7 +190,7 @@ func runContainer(dockerCli command.Cli, opts *runOptions, copts *containerOptio
186190
return runStartContainerErr(err)
187191
}
188192

189-
if (config.AttachStdin || config.AttachStdout || config.AttachStderr) && config.Tty && dockerCli.Out().IsTerminal() {
193+
if attach && config.Tty && dockerCli.Out().IsTerminal() {
190194
if err := MonitorTtySize(ctx, dockerCli, createResponse.ID, false); err != nil {
191195
fmt.Fprintln(stderr, "Error monitoring TTY size:", err)
192196
}

0 commit comments

Comments
 (0)