Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions cli/command/container/attach.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions cli/command/container/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
}

Expand Down
4 changes: 2 additions & 2 deletions cli/command/container/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Loading