From 51d9a04f17d1c8c6c1a069227c1417b20283dda2 Mon Sep 17 00:00:00 2001 From: Michael Crosby Date: Mon, 31 Mar 2014 18:21:07 +0000 Subject: [PATCH] Make sure to set error reguardless of attach or stdin Fixes #3364 Docker-DCO-1.1-Signed-off-by: Michael Crosby (github: crosbymichael) --- api/client/commands.go | 2 +- integration-cli/docker_cli_start_test.go | 34 ++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 integration-cli/docker_cli_start_test.go diff --git a/api/client/commands.go b/api/client/commands.go index 49a5c008b3..49cd07700f 100644 --- a/api/client/commands.go +++ b/api/client/commands.go @@ -607,8 +607,8 @@ func (cli *DockerCli) CmdStart(args ...string) error { if err != nil { if !*attach || !*openStdin { fmt.Fprintf(cli.err, "%s\n", err) - encounteredError = fmt.Errorf("Error: failed to start one or more containers") } + encounteredError = fmt.Errorf("Error: failed to start one or more containers") } else { if !*attach || !*openStdin { fmt.Fprintf(cli.out, "%s\n", name) diff --git a/integration-cli/docker_cli_start_test.go b/integration-cli/docker_cli_start_test.go new file mode 100644 index 0000000000..c3059a66c4 --- /dev/null +++ b/integration-cli/docker_cli_start_test.go @@ -0,0 +1,34 @@ +package main + +import ( + "os/exec" + "testing" +) + +// Regression test for #3364 +func TestDockerStartWithPortCollision(t *testing.T) { + runCmd := exec.Command(dockerBinary, "run", "--name", "fail", "-p", "25:25", "busybox", "true") + out, stderr, exitCode, err := runCommandWithStdoutStderr(runCmd) + if err != nil && exitCode != 0 { + t.Fatal(out, stderr, err) + } + + runCmd = exec.Command(dockerBinary, "run", "--name", "conflict", "-dti", "-p", "25:25", "busybox", "sh") + out, stderr, exitCode, err = runCommandWithStdoutStderr(runCmd) + if err != nil && exitCode != 0 { + t.Fatal(out, stderr, err) + } + + startCmd := exec.Command(dockerBinary, "start", "-a", "fail") + out, stderr, exitCode, err = runCommandWithStdoutStderr(startCmd) + if err != nil && exitCode != 1 { + t.Fatal(out, err) + } + + killCmd := exec.Command(dockerBinary, "kill", "conflict") + runCommand(killCmd) + + deleteAllContainers() + + logDone("start - -a=true error on port use") +}