Browse code

Make sure to set error reguardless of attach or stdin

Fixes #3364
Docker-DCO-1.1-Signed-off-by: Michael Crosby <michael@crosbymichael.com> (github: crosbymichael)

Michael Crosby authored on 2014/04/01 03:21:07
Showing 2 changed files
... ...
@@ -607,8 +607,8 @@ func (cli *DockerCli) CmdStart(args ...string) error {
607 607
 		if err != nil {
608 608
 			if !*attach || !*openStdin {
609 609
 				fmt.Fprintf(cli.err, "%s\n", err)
610
-				encounteredError = fmt.Errorf("Error: failed to start one or more containers")
611 610
 			}
611
+			encounteredError = fmt.Errorf("Error: failed to start one or more containers")
612 612
 		} else {
613 613
 			if !*attach || !*openStdin {
614 614
 				fmt.Fprintf(cli.out, "%s\n", name)
615 615
new file mode 100644
... ...
@@ -0,0 +1,34 @@
0
+package main
1
+
2
+import (
3
+	"os/exec"
4
+	"testing"
5
+)
6
+
7
+// Regression test for #3364
8
+func TestDockerStartWithPortCollision(t *testing.T) {
9
+	runCmd := exec.Command(dockerBinary, "run", "--name", "fail", "-p", "25:25", "busybox", "true")
10
+	out, stderr, exitCode, err := runCommandWithStdoutStderr(runCmd)
11
+	if err != nil && exitCode != 0 {
12
+		t.Fatal(out, stderr, err)
13
+	}
14
+
15
+	runCmd = exec.Command(dockerBinary, "run", "--name", "conflict", "-dti", "-p", "25:25", "busybox", "sh")
16
+	out, stderr, exitCode, err = runCommandWithStdoutStderr(runCmd)
17
+	if err != nil && exitCode != 0 {
18
+		t.Fatal(out, stderr, err)
19
+	}
20
+
21
+	startCmd := exec.Command(dockerBinary, "start", "-a", "fail")
22
+	out, stderr, exitCode, err = runCommandWithStdoutStderr(startCmd)
23
+	if err != nil && exitCode != 1 {
24
+		t.Fatal(out, err)
25
+	}
26
+
27
+	killCmd := exec.Command(dockerBinary, "kill", "conflict")
28
+	runCommand(killCmd)
29
+
30
+	deleteAllContainers()
31
+
32
+	logDone("start - -a=true error on port use")
33
+}