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

Merge pull request #19483 from coolljt0725/fix_19477

Fix #19477, clean up the ports when release network
This commit is contained in:
Vincent Demeester 2016-01-21 14:29:29 +01:00
commit 476edba011
2 changed files with 19 additions and 0 deletions

View file

@ -999,6 +999,8 @@ func (daemon *Daemon) releaseNetwork(container *container.Container) {
sid := container.NetworkSettings.SandboxID
settings := container.NetworkSettings.Networks
container.NetworkSettings.Ports = nil
if sid == "" || len(settings) == 0 {
return
}

View file

@ -638,3 +638,20 @@ func (s *DockerSuite) TestPsImageIDAfterUpdate(c *check.C) {
}
}
func (s *DockerSuite) TestPsNotShowPortsOfStoppedContainer(c *check.C) {
dockerCmd(c, "run", "--name=foo", "-d", "-p", "5000:5000", "busybox", "top")
c.Assert(waitRun("foo"), checker.IsNil)
out, _ := dockerCmd(c, "ps")
lines := strings.Split(strings.TrimSpace(string(out)), "\n")
expected := "0.0.0.0:5000->5000/tcp"
fields := strings.Fields(lines[1])
c.Assert(fields[len(fields)-2], checker.Equals, expected, check.Commentf("Expected: %v, got: %v", expected, fields[len(fields)-2]))
dockerCmd(c, "kill", "foo")
dockerCmd(c, "wait", "foo")
out, _ = dockerCmd(c, "ps", "-l")
lines = strings.Split(strings.TrimSpace(string(out)), "\n")
fields = strings.Fields(lines[1])
c.Assert(fields[len(fields)-2], checker.Not(checker.Equals), expected, check.Commentf("Should not got %v", expected))
}