1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Fix automatically publish ports without --publish-all

Signed-off-by: Lei Jitang <leijitang@huawei.com>
This commit is contained in:
Lei Jitang 2015-05-18 02:57:17 +08:00
parent c2e8f07a05
commit 9a09664b51
2 changed files with 15 additions and 2 deletions

View file

@ -3186,3 +3186,14 @@ func (s *DockerSuite) TestRunUnshareProc(c *check.C) {
c.Fatalf("unshare should have failed with permission denied, got: %s, %v", out, err)
}
}
func (s *DockerSuite) TestRunPublishPort(c *check.C) {
out, _, err := runCommandWithOutput(exec.Command(dockerBinary, "run", "-d", "--name", "test", "--expose", "8080", "busybox", "top"))
c.Assert(err, check.IsNil)
out, _, err = runCommandWithOutput(exec.Command(dockerBinary, "port", "test"))
c.Assert(err, check.IsNil)
out = strings.Trim(out, "\r\n")
if out != "" {
c.Fatalf("run without --publish-all should not publish port, out should be nil, but got: %s", out)
}
}

View file

@ -60,10 +60,10 @@ func SortPortMap(ports []Port, bindings PortMap) {
for _, b := range binding {
s = append(s, portMapEntry{port: p, binding: b})
}
bindings[p] = []PortBinding{}
} else {
s = append(s, portMapEntry{port: p})
}
bindings[p] = []PortBinding{}
}
sort.Sort(s)
@ -79,9 +79,11 @@ func SortPortMap(ports []Port, bindings PortMap) {
i++
}
// reorder bindings for this port
if _, ok := bindings[entry.port]; ok {
bindings[entry.port] = append(bindings[entry.port], entry.binding)
}
}
}
func toInt(s string) int64 {
i, err := strconv.ParseInt(s, 10, 64)