@@ -7283,3 +7283,31 @@ func (s *DockerRegistrySuite) TestBuildWithPublicRegistryBlocked(c *check.C) {
72837283func (s * DockerRegistrySuite ) TestBuildWithAllRegistriesBlocked (c * check.C ) {
72847284 s .doTestBuildWithPublicRegistryBlocked (c , "testbuildwithallregistriesblocked" , []string {"--block-registry=all" })
72857285}
7286+
7287+ func (s * DockerSuite ) TestBuildNetNone (c * check.C ) {
7288+ testRequires (c , DaemonIsLinux )
7289+
7290+ name := "testbuildnetnone"
7291+ _ , out , err := buildImageWithOut (name , `
7292+ FROM busybox
7293+ RUN ping -c 1 8.8.8.8
7294+ ` , true , "--network=none" )
7295+ c .Assert (err , checker .NotNil )
7296+ c .Assert (out , checker .Contains , "unreachable" )
7297+ }
7298+
7299+ func (s * DockerSuite ) TestBuildNetContainer (c * check.C ) {
7300+ testRequires (c , DaemonIsLinux )
7301+
7302+ id , _ := dockerCmd (c , "run" , "--hostname" , "foobar" , "-d" , "busybox" , "nc" , "-ll" , "-p" , "1234" , "-e" , "hostname" )
7303+
7304+ name := "testbuildnetcontainer"
7305+ out , err := buildImage (name , `
7306+ FROM busybox
7307+ RUN nc localhost 1234 > /otherhost
7308+ ` , true , "--network=container:" + strings .TrimSpace (id ))
7309+ c .Assert (err , checker .IsNil , check .Commentf ("out: %v" , out ))
7310+
7311+ host , _ := dockerCmd (c , "run" , "testbuildnetcontainer" , "cat" , "/otherhost" )
7312+ c .Assert (strings .TrimSpace (host ), check .Equals , "foobar" )
7313+ }
0 commit comments