diff --git a/components/engine/commands.go b/components/engine/commands.go index 87aa12b65c..f7895557df 100644 --- a/components/engine/commands.go +++ b/components/engine/commands.go @@ -1347,8 +1347,18 @@ func (cli *DockerCli) CmdLogs(args ...string) error { return nil } name := cmd.Arg(0) + body, _, err := cli.call("GET", "/containers/"+name+"/json", nil) + if err != nil { + return err + } - if err := cli.hijack("POST", "/containers/"+name+"/attach?logs=1&stdout=1&stderr=1", false, nil, cli.out, cli.err, nil); err != nil { + container := &Container{} + err = json.Unmarshal(body, container) + if err != nil { + return err + } + + if err := cli.hijack("POST", "/containers/"+name+"/attach?logs=1&stdout=1&stderr=1", container.Config.Tty, nil, cli.out, cli.err, nil); err != nil { return err } return nil diff --git a/components/engine/commands_test.go b/components/engine/commands_test.go index 67eae04b19..2c0e319787 100644 --- a/components/engine/commands_test.go +++ b/components/engine/commands_test.go @@ -645,3 +645,19 @@ func TestRunAutoRemove(t *testing.T) { t.Fatalf("failed to remove container automatically: container %s still exists", temporaryContainerID) } } + +func TestCmdLogs(t *testing.T) { + cli := NewDockerCli(nil, ioutil.Discard, ioutil.Discard, testDaemonProto, testDaemonAddr) + defer cleanup(globalRuntime) + + if err := cli.CmdRun(unitTestImageID, "sh", "-c", "ls -l"); err != nil { + t.Fatal(err) + } + if err := cli.CmdRun("-t", unitTestImageID, "sh", "-c", "ls -l"); err != nil { + t.Fatal(err) + } + + if err := cli.CmdLogs(globalRuntime.List()[0].ID); err != nil { + t.Fatal(err) + } +}