Pārlūkot izejas kodu

Merge pull request #2499 from dotcloud/2414-logs_tty-fix

Fix logs with tty
Michael Crosby 11 gadi atpakaļ
vecāks
revīzija
57cd17f656
2 mainītis faili ar 27 papildinājumiem un 1 dzēšanām
  1. 11 1
      commands.go
  2. 16 0
      commands_test.go

+ 11 - 1
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
+	}
+
+	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", false, nil, cli.out, cli.err, nil); err != nil {
+	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

+ 16 - 0
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)
+	}
+}