Browse code

Fix #19477, clean up the ports when release network

Signed-off-by: Lei Jitang <leijitang@huawei.com>

Lei Jitang authored on 2016/01/21 10:09:11
Showing 2 changed files
... ...
@@ -999,6 +999,8 @@ func (daemon *Daemon) releaseNetwork(container *container.Container) {
999 999
 
1000 1000
 	sid := container.NetworkSettings.SandboxID
1001 1001
 	settings := container.NetworkSettings.Networks
1002
+	container.NetworkSettings.Ports = nil
1003
+
1002 1004
 	if sid == "" || len(settings) == 0 {
1003 1005
 		return
1004 1006
 	}
... ...
@@ -638,3 +638,20 @@ func (s *DockerSuite) TestPsImageIDAfterUpdate(c *check.C) {
638 638
 	}
639 639
 
640 640
 }
641
+
642
+func (s *DockerSuite) TestPsNotShowPortsOfStoppedContainer(c *check.C) {
643
+	dockerCmd(c, "run", "--name=foo", "-d", "-p", "5000:5000", "busybox", "top")
644
+	c.Assert(waitRun("foo"), checker.IsNil)
645
+	out, _ := dockerCmd(c, "ps")
646
+	lines := strings.Split(strings.TrimSpace(string(out)), "\n")
647
+	expected := "0.0.0.0:5000->5000/tcp"
648
+	fields := strings.Fields(lines[1])
649
+	c.Assert(fields[len(fields)-2], checker.Equals, expected, check.Commentf("Expected: %v, got: %v", expected, fields[len(fields)-2]))
650
+
651
+	dockerCmd(c, "kill", "foo")
652
+	dockerCmd(c, "wait", "foo")
653
+	out, _ = dockerCmd(c, "ps", "-l")
654
+	lines = strings.Split(strings.TrimSpace(string(out)), "\n")
655
+	fields = strings.Fields(lines[1])
656
+	c.Assert(fields[len(fields)-2], checker.Not(checker.Equals), expected, check.Commentf("Should not got %v", expected))
657
+}