From 3109fc9537682a7b9ee566f3674484b1b2296707 Mon Sep 17 00:00:00 2001 From: Tibor Vass Date: Fri, 5 Sep 2014 18:59:31 -0700 Subject: [PATCH] Add Test for port allocation bug (port already in use by other programs than docker) Signed-off-by: Tibor Vass --- integration-cli/docker_cli_run_test.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/integration-cli/docker_cli_run_test.go b/integration-cli/docker_cli_run_test.go index e781f3782a..1dc0e41b0f 100644 --- a/integration-cli/docker_cli_run_test.go +++ b/integration-cli/docker_cli_run_test.go @@ -4,6 +4,7 @@ import ( "bufio" "fmt" "io/ioutil" + "net" "os" "os/exec" "path" @@ -1875,3 +1876,21 @@ func TestRunDeallocatePortOnMissingIptablesRule(t *testing.T) { deleteAllContainers() logDone("run - port should be deallocated even on iptables error") } + +func TestRunPortInUse(t *testing.T) { + port := "1234" + l, err := net.Listen("tcp", ":"+port) + if err != nil { + t.Fatal(err) + } + defer l.Close() + cmd := exec.Command(dockerBinary, "run", "-p", port+":80", "busybox", "true") + out, _, err := runCommandWithOutput(cmd) + if err == nil { + t.Fatalf("Host port %s already in use, has been allocated by docker: %q", port, out) + } + + deleteAllContainers() + + logDone("run - port in use") +}