diff --git a/cli/run.go b/cli/run.go index 1d67da1cb..c56534c54 100644 --- a/cli/run.go +++ b/cli/run.go @@ -106,6 +106,10 @@ func (rc *RunCommand) runRun(args []string) error { wait := make(chan struct{}) + if err := checkTty(rc.stdin, rc.tty, os.Stdout.Fd()); err != nil { + return err + } + if rc.attach || rc.stdin { if rc.tty { in, out, err := setRawMode(rc.stdin, false) diff --git a/test/cli_run_test.go b/test/cli_run_test.go index c002947dd..dbc672e44 100644 --- a/test/cli_run_test.go +++ b/test/cli_run_test.go @@ -13,6 +13,7 @@ import ( "github.com/go-check/check" "github.com/gotestyourself/gotestyourself/icmd" + "github.com/stretchr/testify/assert" ) // PouchRunSuite is the test suite for run CLI. @@ -443,3 +444,13 @@ func (suite *PouchRunSuite) TestRunWithEnv(c *check.C) { res.Assert(c, icmd.Success) c.Assert(strings.TrimSpace(res.Stdout()), check.Equals, "a,b,c-b1") } + +// TestRunWithTty tests running container with -tty flag and attach stdin in a non-tty client. +func (suite *PouchRunSuite) TestRunWithTty(c *check.C) { + name := "TestRunWithTty" + res := command.PouchRun("run", "-i", "-t", "--name", name, busyboxImage, "sleep", "100000") + defer DelContainerForceMultyTime(c, name) + + errString := res.Stderr() + assert.Equal(c, errString, "Error: the input device is not a TTY\n") +}