Move port-mapping ownership closer to Sandbox (from Endpoint)

https://github.com/docker/libnetwork/pull/810 provides the more complete
solution for moving the Port-mapping ownership away from endpoint and
into Sandbox. But, this PR makes the best use of existing libnetwork
design and get a step closer to the gaol.

Signed-off-by: Madhu Venugopal <madhu@docker.com>
Upstream-commit: e38463b2779f455b4173171d5a1fdb115180a7e9
Component: engine
This commit is contained in:
Madhu Venugopal
2016-01-26 03:59:03 -08:00
parent 36c72742b4
commit 578fa2d8c0
3 changed files with 81 additions and 31 deletions
@@ -293,3 +293,24 @@ func (s *DockerSuite) TestPortExposeHostBinding(c *check.C) {
// Port is still bound after the Container is removed
c.Assert(err, checker.NotNil, check.Commentf("out: %s", out))
}
func (s *DockerSuite) TestPortBindingOnSandbox(c *check.C) {
testRequires(c, DaemonIsLinux, NotUserNamespace)
dockerCmd(c, "network", "create", "--internal", "-d", "bridge", "internal-net")
dockerCmd(c, "run", "--net", "internal-net", "-d", "--name", "c1",
"-p", "8080:8080", "busybox", "nc", "-l", "-p", "8080")
c.Assert(waitRun("c1"), check.IsNil)
_, _, err := dockerCmdWithError("run", "--net=host", "busybox", "nc", "localhost", "8080")
c.Assert(err, check.NotNil,
check.Commentf("Port mapping on internal network is expected to fail"))
// Connect container to another normal bridge network
dockerCmd(c, "network", "create", "-d", "bridge", "foo-net")
dockerCmd(c, "network", "connect", "foo-net", "c1")
_, _, err = dockerCmdWithError("run", "--net=host", "busybox", "nc", "localhost", "8080")
c.Assert(err, check.IsNil,
check.Commentf("Port mapping on the new network is expected to succeed"))
}