mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Merge pull request #22984 from Microsoft/jjh/ttymessage
Better error on attach no tty
This commit is contained in:
commit
24d2ee8c48
4 changed files with 21 additions and 5 deletions
|
@ -67,7 +67,11 @@ func (cli *DockerCli) CheckTtyInput(attachStdin, ttyMode bool) error {
|
||||||
// be a tty itself: redirecting or piping the client standard input is
|
// be a tty itself: redirecting or piping the client standard input is
|
||||||
// incompatible with `docker run -t`, `docker exec -t` or `docker attach`.
|
// incompatible with `docker run -t`, `docker exec -t` or `docker attach`.
|
||||||
if ttyMode && attachStdin && !cli.isTerminalIn {
|
if ttyMode && attachStdin && !cli.isTerminalIn {
|
||||||
return errors.New("cannot enable tty mode on non tty input")
|
eText := "the input device is not a TTY"
|
||||||
|
if runtime.GOOS == "windows" {
|
||||||
|
return errors.New(eText + ". If you are using mintty, try prefixing the command with 'winpty'")
|
||||||
|
}
|
||||||
|
return errors.New(eText)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
|
"runtime"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
@ -103,7 +104,10 @@ func (s *DockerSuite) TestAttachTTYWithoutStdin(c *check.C) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
expected := "cannot enable tty mode"
|
expected := "the input device is not a TTY"
|
||||||
|
if runtime.GOOS == "windows" {
|
||||||
|
expected += ". If you are using mintty, try prefixing the command with 'winpty'"
|
||||||
|
}
|
||||||
if out, _, err := runCommandWithOutput(cmd); err == nil {
|
if out, _, err := runCommandWithOutput(cmd); err == nil {
|
||||||
done <- fmt.Errorf("attach should have failed")
|
done <- fmt.Errorf("attach should have failed")
|
||||||
return
|
return
|
||||||
|
|
|
@ -9,6 +9,7 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"reflect"
|
"reflect"
|
||||||
|
"runtime"
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
@ -182,7 +183,10 @@ func (s *DockerSuite) TestExecTTYWithoutStdin(c *check.C) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
expected := "cannot enable tty mode"
|
expected := "the input device is not a TTY"
|
||||||
|
if runtime.GOOS == "windows" {
|
||||||
|
expected += ". If you are using mintty, try prefixing the command with 'winpty'"
|
||||||
|
}
|
||||||
if out, _, err := runCommandWithOutput(cmd); err == nil {
|
if out, _, err := runCommandWithOutput(cmd); err == nil {
|
||||||
errChan <- fmt.Errorf("exec should have failed")
|
errChan <- fmt.Errorf("exec should have failed")
|
||||||
return
|
return
|
||||||
|
|
|
@ -12,6 +12,7 @@ import (
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"reflect"
|
"reflect"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
"runtime"
|
||||||
"sort"
|
"sort"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -2642,7 +2643,10 @@ func (s *DockerSuite) TestRunTTYWithPipe(c *check.C) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
expected := "cannot enable tty mode"
|
expected := "the input device is not a TTY"
|
||||||
|
if runtime.GOOS == "windows" {
|
||||||
|
expected += ". If you are using mintty, try prefixing the command with 'winpty'"
|
||||||
|
}
|
||||||
if out, _, err := runCommandWithOutput(cmd); err == nil {
|
if out, _, err := runCommandWithOutput(cmd); err == nil {
|
||||||
errChan <- fmt.Errorf("run should have failed")
|
errChan <- fmt.Errorf("run should have failed")
|
||||||
return
|
return
|
||||||
|
@ -2655,7 +2659,7 @@ func (s *DockerSuite) TestRunTTYWithPipe(c *check.C) {
|
||||||
select {
|
select {
|
||||||
case err := <-errChan:
|
case err := <-errChan:
|
||||||
c.Assert(err, check.IsNil)
|
c.Assert(err, check.IsNil)
|
||||||
case <-time.After(6 * time.Second):
|
case <-time.After(30 * time.Second):
|
||||||
c.Fatal("container is running but should have failed")
|
c.Fatal("container is running but should have failed")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue