mirror of
https://github.com/docker/docs.git
synced 2026-04-12 06:19:22 +07:00
Try other port on any error from Map
Sometimes other programs can bind on ports from our range, so we just skip this ports on allocation. Fixes #9293 Probably fixes #8714 Signed-off-by: Alexander Morozov <lk4d4@docker.com>
This commit is contained in:
committed by
Alexander Morozov
parent
92c840c87d
commit
a00a1a1fca
@@ -2701,3 +2701,44 @@ func TestRunTLSverify(t *testing.T) {
|
||||
|
||||
logDone("run - verify tls is set for --tlsverify")
|
||||
}
|
||||
|
||||
func TestRunPortFromDockerRangeInUse(t *testing.T) {
|
||||
defer deleteAllContainers()
|
||||
// first find allocator current position
|
||||
cmd := exec.Command(dockerBinary, "run", "-d", "-p", ":80", "busybox", "top")
|
||||
out, _, err := runCommandWithOutput(cmd)
|
||||
if err != nil {
|
||||
t.Fatal(out, err)
|
||||
}
|
||||
id := strings.TrimSpace(out)
|
||||
cmd = exec.Command(dockerBinary, "port", id)
|
||||
out, _, err = runCommandWithOutput(cmd)
|
||||
if err != nil {
|
||||
t.Fatal(out, err)
|
||||
}
|
||||
out = strings.TrimSpace(out)
|
||||
out = strings.Split(out, ":")[1]
|
||||
lastPort, err := strconv.Atoi(out)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
port := lastPort + 1
|
||||
l, err := net.Listen("tcp", ":"+strconv.Itoa(port))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer l.Close()
|
||||
cmd = exec.Command(dockerBinary, "run", "-d", "-p", ":80", "busybox", "top")
|
||||
out, _, err = runCommandWithOutput(cmd)
|
||||
if err != nil {
|
||||
t.Fatalf(out, err)
|
||||
}
|
||||
id = strings.TrimSpace(out)
|
||||
cmd = exec.Command(dockerBinary, "port", id)
|
||||
out, _, err = runCommandWithOutput(cmd)
|
||||
if err != nil {
|
||||
t.Fatal(out, err)
|
||||
}
|
||||
|
||||
logDone("run - find another port if port from autorange already bound")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user