mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Fix building image error if bridge network is disabled
Signed-off-by: Chun Chen <ramichen@tencent.com>
This commit is contained in:
parent
bf7bae9662
commit
a8d013495c
4 changed files with 30 additions and 1 deletions
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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")
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue