From bd6d500d90310438e7c4efd6bee7fbbfc5f0f2a6 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Wed, 1 Apr 2026 15:38:29 +0200 Subject: [PATCH] cli/command/container: inline uses of streams.Out.CheckTty Signed-off-by: Sebastiaan van Stijn --- cli/command/container/attach.go | 13 ++++++++++--- cli/command/container/exec.go | 4 ++-- cli/command/container/run.go | 4 ++-- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/cli/command/container/attach.go b/cli/command/container/attach.go index f31a13f27b86..a9edbb9e487a 100644 --- a/cli/command/container/attach.go +++ b/cli/command/container/attach.go @@ -89,13 +89,20 @@ func RunAttach(ctx context.Context, dockerCLI command.Cli, containerID string, o return err } - if err := dockerCLI.In().CheckTty(!opts.NoStdin, c.Config.Tty); err != nil { - return err + attachStdin := !opts.NoStdin + if attachStdin { + // TODO(thaJeztah): should this also check if c.Config.OpenStdin is true, and produce an error otherwise? + if !c.Config.Tty { + return errors.New("cannot attach stdin because the container is not a TTY-enabled container") + } + if !dockerCLI.In().IsTerminal() { + return errors.New("cannot attach stdin because stdin is not a terminal") + } } options := client.ContainerAttachOptions{ Stream: true, - Stdin: !opts.NoStdin && c.Config.OpenStdin, + Stdin: attachStdin && c.Config.OpenStdin, Stdout: true, Stderr: true, DetachKeys: detachKeys, diff --git a/cli/command/container/exec.go b/cli/command/container/exec.go index bd4f9bc6242c..813285d65f83 100644 --- a/cli/command/container/exec.go +++ b/cli/command/container/exec.go @@ -101,8 +101,8 @@ func RunExec(ctx context.Context, dockerCLI command.Cli, containerIDorName strin return err } if !options.Detach { - if err := dockerCLI.In().CheckTty(execOptions.AttachStdin, execOptions.TTY); err != nil { - return err + if execOptions.AttachStdin && execOptions.TTY && !dockerCLI.In().IsTerminal() { + return errors.New("cannot attach stdin to a TTY-enabled container because stdin is not a terminal") } } diff --git a/cli/command/container/run.go b/cli/command/container/run.go index 3c25630d6b78..794f3253d2d5 100644 --- a/cli/command/container/run.go +++ b/cli/command/container/run.go @@ -126,8 +126,8 @@ func runContainer(ctx context.Context, dockerCli command.Cli, runOpts *runOption config.ArgsEscaped = false if !runOpts.detach { - if err := dockerCli.In().CheckTty(config.AttachStdin, config.Tty); err != nil { - return err + if config.AttachStdin && config.Tty && !dockerCli.In().IsTerminal() { + return errors.New("cannot attach stdin to a TTY-enabled container because stdin is not a terminal") } } else { if copts.attach.Len() != 0 {