diff --git a/daemon/create.go b/daemon/create.go index eea3a1351d..188e6b5b38 100644 --- a/daemon/create.go +++ b/daemon/create.go @@ -9,6 +9,7 @@ import ( "github.com/docker/docker/layer" "github.com/docker/docker/pkg/idtools" "github.com/docker/docker/pkg/stringid" + "github.com/docker/docker/runconfig" volumestore "github.com/docker/docker/volume/store" "github.com/docker/engine-api/types" containertypes "github.com/docker/engine-api/types/container" @@ -122,6 +123,9 @@ func (daemon *Daemon) create(params types.ContainerCreateConfig) (retC *containe if params.NetworkingConfig != nil { endpointsConfigs = params.NetworkingConfig.EndpointsConfig } + // Make sure NetworkMode has an acceptable value. We do this to ensure + // backwards API compatibility. + container.HostConfig = runconfig.SetDefaultNetModeIfBlank(container.HostConfig) if err := daemon.updateContainerNetworkSettings(container, endpointsConfigs); err != nil { return nil, err diff --git a/integration-cli/daemon.go b/integration-cli/daemon.go index 35ca0b081a..ca85888ed4 100644 --- a/integration-cli/daemon.go +++ b/integration-cli/daemon.go @@ -486,3 +486,8 @@ func (d *Daemon) findContainerIP(id string) string { } return strings.Trim(out, " \r\n'") } + +func (d *Daemon) buildImageWithOut(name, dockerfile string, useCache bool, buildFlags ...string) (string, int, error) { + buildCmd := buildImageCmdWithHost(name, dockerfile, d.sock(), useCache, buildFlags...) + return runCommandWithOutput(buildCmd) +} diff --git a/integration-cli/docker_cli_daemon_test.go b/integration-cli/docker_cli_daemon_test.go index 71fd581822..f4a352ec06 100644 --- a/integration-cli/docker_cli_daemon_test.go +++ b/integration-cli/docker_cli_daemon_test.go @@ -2320,3 +2320,15 @@ func (s *DockerDaemonSuite) TestDaemonMaxConcurrencyWithConfigFileReload(c *chec c.Assert(string(content), checker.Contains, expectedMaxConcurrentUploads) c.Assert(string(content), checker.Contains, expectedMaxConcurrentDownloads) } + +func (s *DockerDaemonSuite) TestBuildOnDisabledBridgeNetworkDaemon(c *check.C) { + err := s.d.Start("-b=none", "--iptables=false") + c.Assert(err, check.IsNil) + s.d.c.Logf("dockerBinary %s", dockerBinary) + out, code, err := s.d.buildImageWithOut("busyboxs", + `FROM busybox + RUN cat /etc/hosts`, false) + comment := check.Commentf("Failed to build image. output %s, exitCode %d, err %v", out, code, err) + c.Assert(err, check.IsNil, comment) + c.Assert(code, check.Equals, 0, comment) +} diff --git a/integration-cli/docker_utils.go b/integration-cli/docker_utils.go index 7e30860d92..c2d3fcb153 100644 --- a/integration-cli/docker_utils.go +++ b/integration-cli/docker_utils.go @@ -930,7 +930,15 @@ func getContainerState(c *check.C, id string) (int, bool, error) { } func buildImageCmd(name, dockerfile string, useCache bool, buildFlags ...string) *exec.Cmd { - args := []string{"build", "-t", name} + return buildImageCmdWithHost(name, dockerfile, "", useCache, buildFlags...) +} + +func buildImageCmdWithHost(name, dockerfile, host string, useCache bool, buildFlags ...string) *exec.Cmd { + args := []string{} + if host != "" { + args = append(args, "--host", host) + } + args = append(args, "build", "-t", name) if !useCache { args = append(args, "--no-cache") }