From 1e06654dd0da87599e29913f4934811ad475e7ea Mon Sep 17 00:00:00 2001 From: Aleksa Sarai Date: Wed, 13 Mar 2019 08:25:53 +1100 Subject: [PATCH] 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 --- cli/command/container/run.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/cli/command/container/run.go b/cli/command/container/run.go index 2ce3f3679c59..5b3df3cae012 100644 --- a/cli/command/container/run.go +++ b/cli/command/container/run.go @@ -166,7 +166,11 @@ func runContainer(dockerCli command.Cli, opts *runOptions, copts *containerOptio defer close() } - statusChan := waitExitOrRemoved(ctx, dockerCli, createResponse.ID, copts.autoRemove) + // We don't need to wait if we're not attaching. + var statusChan <-chan int + if attach { + statusChan = waitExitOrRemoved(ctx, dockerCli, createResponse.ID, copts.autoRemove) + } //start the container if err := client.ContainerStart(ctx, createResponse.ID, types.ContainerStartOptions{}); err != nil { @@ -186,7 +190,7 @@ func runContainer(dockerCli command.Cli, opts *runOptions, copts *containerOptio return runStartContainerErr(err) } - if (config.AttachStdin || config.AttachStdout || config.AttachStderr) && config.Tty && dockerCli.Out().IsTerminal() { + if attach && config.Tty && dockerCli.Out().IsTerminal() { if err := MonitorTtySize(ctx, dockerCli, createResponse.ID, false); err != nil { fmt.Fprintln(stderr, "Error monitoring TTY size:", err) }