mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Fix #19477, clean up the ports when release network
Signed-off-by: Lei Jitang <leijitang@huawei.com>
This commit is contained in:
parent
528ebe6ed1
commit
326de12d8f
2 changed files with 19 additions and 0 deletions
|
@ -999,6 +999,8 @@ func (daemon *Daemon) releaseNetwork(container *container.Container) {
|
||||||
|
|
||||||
sid := container.NetworkSettings.SandboxID
|
sid := container.NetworkSettings.SandboxID
|
||||||
settings := container.NetworkSettings.Networks
|
settings := container.NetworkSettings.Networks
|
||||||
|
container.NetworkSettings.Ports = nil
|
||||||
|
|
||||||
if sid == "" || len(settings) == 0 {
|
if sid == "" || len(settings) == 0 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -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))
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue