mirror of
https://github.com/clearlinux/docker.git
synced 2026-09-06 05:31:47 +00:00
sort ports mapping before allocating
prioritize the ports with static mapping before dynamic mapping. This removes the port conflicts when we allocate static port in the reserved range together with dynamic ones. When static port is allocated first, Docker will skip those when determining free ports for dynamic ones. Signed-off-by: Daniel, Dao Quang Minh <dqminh89@gmail.com>
This commit is contained in:
@@ -2243,6 +2243,39 @@ func (s *DockerSuite) TestRunPortProxy(c *check.C) {
|
||||
}
|
||||
}
|
||||
|
||||
// https://github.com/docker/docker/issues/12148
|
||||
func (s *DockerSuite) TestRunAllocatePortInReservedRange(c *check.C) {
|
||||
// allocate a dynamic port to get the most recent
|
||||
cmd := exec.Command(dockerBinary, "run", "-d", "-P", "-p", "80", "busybox", "top")
|
||||
out, _, err := runCommandWithOutput(cmd)
|
||||
if err != nil {
|
||||
c.Fatalf("Failed to run, output: %s, error: %s", out, err)
|
||||
}
|
||||
id := strings.TrimSpace(out)
|
||||
|
||||
cmd = exec.Command(dockerBinary, "port", id, "80")
|
||||
out, _, err = runCommandWithOutput(cmd)
|
||||
if err != nil {
|
||||
c.Fatalf("Failed to get port, output: %s, error: %s", out, err)
|
||||
}
|
||||
strPort := strings.Split(strings.TrimSpace(out), ":")[1]
|
||||
port, err := strconv.ParseInt(strPort, 10, 64)
|
||||
if err != nil {
|
||||
c.Fatalf("invalid port, got: %s, error: %s", strPort, err)
|
||||
}
|
||||
|
||||
// allocate a static port and a dynamic port together, with static port
|
||||
// takes the next recent port in dynamic port range.
|
||||
cmd = exec.Command(dockerBinary, "run", "-d", "-P",
|
||||
"-p", "80",
|
||||
"-p", fmt.Sprintf("%d:8080", port+1),
|
||||
"busybox", "top")
|
||||
out, _, err = runCommandWithOutput(cmd)
|
||||
if err != nil {
|
||||
c.Fatalf("Failed to run, output: %s, error: %s", out, err)
|
||||
}
|
||||
}
|
||||
|
||||
// Regression test for #7792
|
||||
func (s *DockerSuite) TestRunMountOrdering(c *check.C) {
|
||||
testRequires(c, SameHostDaemon)
|
||||
|
||||
Reference in New Issue
Block a user