Merge pull request #27702 from tonistiigi/net-builder0

add --network option for docker build
Upstream-commit: 62ff3e90835c3c572051afbbbac53303e57a5c89
Component: engine
This commit is contained in:
Sebastiaan van Stijn
2016-10-25 21:50:33 -07:00
committed by GitHub
11 changed files with 53 additions and 1 deletions

View File

@ -7078,3 +7078,31 @@ func (s *DockerSuite) TestBuildCacheFrom(c *check.C) {
}
c.Assert(layers1[len(layers1)-1], checker.Not(checker.Equals), layers2[len(layers1)-1])
}
func (s *DockerSuite) TestBuildNetNone(c *check.C) {
testRequires(c, DaemonIsLinux)
name := "testbuildnetnone"
_, out, err := buildImageWithOut(name, `
FROM busybox
RUN ping -c 1 8.8.8.8
`, true, "--network=none")
c.Assert(err, checker.NotNil)
c.Assert(out, checker.Contains, "unreachable")
}
func (s *DockerSuite) TestBuildNetContainer(c *check.C) {
testRequires(c, DaemonIsLinux)
id, _ := dockerCmd(c, "run", "--hostname", "foobar", "-d", "busybox", "nc", "-ll", "-p", "1234", "-e", "hostname")
name := "testbuildnetcontainer"
out, err := buildImage(name, `
FROM busybox
RUN nc localhost 1234 > /otherhost
`, true, "--network=container:"+strings.TrimSpace(id))
c.Assert(err, checker.IsNil, check.Commentf("out: %v", out))
host, _ := dockerCmd(c, "run", "testbuildnetcontainer", "cat", "/otherhost")
c.Assert(strings.TrimSpace(host), check.Equals, "foobar")
}