mirror of
https://github.com/clearlinux/docker.git
synced 2026-08-19 12:16:30 +00:00
fixed incorrect assumption on --bridge=none treated as disable network
libnetwork host, none and bridge driver initialization is incorrectly disabled if the daemon flag --bridge=none. The expected behavior of setting --bridge as none is to disable the bridge driver alone and let all other modes to be operational. Signed-off-by: Madhu Venugopal <madhu@docker.com> Signed-off-by: David Calavera <david.calavera@gmail.com> Conflicts: daemon/container_linux.go daemon/daemon.go daemon/daemon_unix.go daemon/daemon_windows.go
This commit is contained in:
committed by
David Calavera
parent
7e8cceb05a
commit
34815f3fa6
+18
-18
@@ -14,24 +14,24 @@ const (
|
||||
// CommonConfig defines the configuration of a docker daemon which are
|
||||
// common across platforms.
|
||||
type CommonConfig struct {
|
||||
AutoRestart bool
|
||||
Context map[string][]string
|
||||
CorsHeaders string
|
||||
DisableNetwork bool
|
||||
Dns []string
|
||||
DnsSearch []string
|
||||
EnableCors bool
|
||||
ExecDriver string
|
||||
ExecOptions []string
|
||||
ExecRoot string
|
||||
GraphDriver string
|
||||
GraphOptions []string
|
||||
Labels []string
|
||||
LogConfig runconfig.LogConfig
|
||||
Mtu int
|
||||
Pidfile string
|
||||
Root string
|
||||
TrustKeyPath string
|
||||
AutoRestart bool
|
||||
Context map[string][]string
|
||||
CorsHeaders string
|
||||
DisableBridge bool
|
||||
Dns []string
|
||||
DnsSearch []string
|
||||
EnableCors bool
|
||||
ExecDriver string
|
||||
ExecOptions []string
|
||||
ExecRoot string
|
||||
GraphDriver string
|
||||
GraphOptions []string
|
||||
Labels []string
|
||||
LogConfig runconfig.LogConfig
|
||||
Mtu int
|
||||
Pidfile string
|
||||
Root string
|
||||
TrustKeyPath string
|
||||
}
|
||||
|
||||
// InstallCommonFlags adds command-line options to the top-level flag parser for
|
||||
|
||||
@@ -469,7 +469,7 @@ func (container *Container) buildJoinOptions() ([]libnetwork.EndpointOption, err
|
||||
logrus.Error(err)
|
||||
}
|
||||
|
||||
if c != nil && !container.daemon.config.DisableNetwork && container.hostConfig.NetworkMode.IsPrivate() {
|
||||
if c != nil && !container.daemon.config.DisableBridge && container.hostConfig.NetworkMode.IsPrivate() {
|
||||
logrus.Debugf("Update /etc/hosts of %s for alias %s with ip %s", c.ID, ref.Name, container.NetworkSettings.IPAddress)
|
||||
joinOptions = append(joinOptions, libnetwork.JoinOptionParentUpdate(c.NetworkSettings.EndpointID, ref.Name, container.NetworkSettings.IPAddress))
|
||||
if c.NetworkSettings.EndpointID != "" {
|
||||
@@ -753,6 +753,11 @@ func (container *Container) AllocateNetwork() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
if mode.IsBridge() && container.daemon.config.DisableBridge {
|
||||
container.Config.NetworkDisabled = true
|
||||
return nil
|
||||
}
|
||||
|
||||
var err error
|
||||
|
||||
n, err := container.daemon.netController.NetworkByName(string(mode))
|
||||
@@ -817,10 +822,6 @@ func (container *Container) initializeNetworking() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
if container.daemon.config.DisableNetwork {
|
||||
container.Config.NetworkDisabled = true
|
||||
}
|
||||
|
||||
if container.hostConfig.NetworkMode.IsHost() {
|
||||
container.Config.Hostname, err = os.Hostname()
|
||||
if err != nil {
|
||||
@@ -939,7 +940,7 @@ func (container *Container) getNetworkedContainer() (*Container, error) {
|
||||
}
|
||||
|
||||
func (container *Container) ReleaseNetwork() {
|
||||
if container.hostConfig.NetworkMode.IsContainer() || container.daemon.config.DisableNetwork {
|
||||
if container.hostConfig.NetworkMode.IsContainer() || container.Config.NetworkDisabled {
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
+22
-15
@@ -683,7 +683,7 @@ func NewDaemon(config *Config, registryService *registry.Service) (daemon *Daemo
|
||||
if !config.Bridge.EnableIPTables && config.Bridge.EnableIPMasq {
|
||||
config.Bridge.EnableIPMasq = false
|
||||
}
|
||||
config.DisableNetwork = config.Bridge.Iface == disableNetworkBridge
|
||||
config.DisableBridge = config.Bridge.Iface == disableNetworkBridge
|
||||
|
||||
// Check that the system is supported and we have sufficient privileges
|
||||
if runtime.GOOS != "linux" {
|
||||
@@ -820,11 +820,9 @@ func NewDaemon(config *Config, registryService *registry.Service) (daemon *Daemo
|
||||
return nil, fmt.Errorf("Couldn't create Tag store: %s", err)
|
||||
}
|
||||
|
||||
if !config.DisableNetwork {
|
||||
d.netController, err = initNetworkController(config)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("Error initializing network controller: %v", err)
|
||||
}
|
||||
d.netController, err = initNetworkController(config)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("Error initializing network controller: %v", err)
|
||||
}
|
||||
|
||||
graphdbPath := path.Join(config.Root, "linkgraph.db")
|
||||
@@ -912,12 +910,22 @@ func initNetworkController(config *Config) (libnetwork.NetworkController, error)
|
||||
return nil, fmt.Errorf("Error creating default \"host\" network: %v", err)
|
||||
}
|
||||
|
||||
// Initialize default driver "bridge"
|
||||
if !config.DisableBridge {
|
||||
// Initialize default driver "bridge"
|
||||
if err := initBridgeDriver(controller, config); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
return controller, nil
|
||||
}
|
||||
|
||||
func initBridgeDriver(controller libnetwork.NetworkController, config *Config) error {
|
||||
option := options.Generic{
|
||||
"EnableIPForwarding": config.Bridge.EnableIPForward}
|
||||
|
||||
if err := controller.ConfigureNetworkDriver("bridge", options.Generic{netlabel.GenericData: option}); err != nil {
|
||||
return nil, fmt.Errorf("Error initializing bridge driver: %v", err)
|
||||
return fmt.Errorf("Error initializing bridge driver: %v", err)
|
||||
}
|
||||
|
||||
netOption := options.Generic{
|
||||
@@ -932,7 +940,7 @@ func initNetworkController(config *Config) (libnetwork.NetworkController, error)
|
||||
if config.Bridge.IP != "" {
|
||||
ip, bipNet, err := net.ParseCIDR(config.Bridge.IP)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return err
|
||||
}
|
||||
|
||||
bipNet.IP = ip
|
||||
@@ -942,7 +950,7 @@ func initNetworkController(config *Config) (libnetwork.NetworkController, error)
|
||||
if config.Bridge.FixedCIDR != "" {
|
||||
_, fCIDR, err := net.ParseCIDR(config.Bridge.FixedCIDR)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return err
|
||||
}
|
||||
|
||||
netOption["FixedCIDR"] = fCIDR
|
||||
@@ -951,7 +959,7 @@ func initNetworkController(config *Config) (libnetwork.NetworkController, error)
|
||||
if config.Bridge.FixedCIDRv6 != "" {
|
||||
_, fCIDRv6, err := net.ParseCIDR(config.Bridge.FixedCIDRv6)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return err
|
||||
}
|
||||
|
||||
netOption["FixedCIDRv6"] = fCIDRv6
|
||||
@@ -971,16 +979,15 @@ func initNetworkController(config *Config) (libnetwork.NetworkController, error)
|
||||
}
|
||||
|
||||
// Initialize default network on "bridge" with the same name
|
||||
_, err = controller.NewNetwork("bridge", "bridge",
|
||||
_, err := controller.NewNetwork("bridge", "bridge",
|
||||
libnetwork.NetworkOptionGeneric(options.Generic{
|
||||
netlabel.GenericData: netOption,
|
||||
netlabel.EnableIPv6: config.Bridge.EnableIPv6,
|
||||
}))
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("Error creating default \"bridge\" network: %v", err)
|
||||
return fmt.Errorf("Error creating default \"bridge\" network: %v", err)
|
||||
}
|
||||
|
||||
return controller, nil
|
||||
return nil
|
||||
}
|
||||
|
||||
func (daemon *Daemon) Shutdown() error {
|
||||
|
||||
@@ -1207,7 +1207,12 @@ func (s *DockerDaemonSuite) TestRunContainerWithBridgeNone(c *check.C) {
|
||||
out, err := s.d.Cmd("run", "--rm", "busybox", "ip", "l")
|
||||
c.Assert(err, check.IsNil, check.Commentf("Output: %s", out))
|
||||
c.Assert(strings.Contains(out, "eth0"), check.Equals, false,
|
||||
check.Commentf("There shouldn't be eth0 in container when network is disabled: %s", out))
|
||||
check.Commentf("There shouldn't be eth0 in container in default(bridge) mode when bridge network is disabled: %s", out))
|
||||
|
||||
out, err = s.d.Cmd("run", "--rm", "--net=host", "busybox", "ip", "l")
|
||||
c.Assert(err, check.IsNil, check.Commentf("Output: %s", out))
|
||||
c.Assert(strings.Contains(out, "eth0"), check.Equals, true,
|
||||
check.Commentf("There should be eth0 in container when --net=host when bridge network is disabled: %s", out))
|
||||
}
|
||||
|
||||
func (s *DockerDaemonSuite) TestDaemonRestartWithContainerRunning(t *check.C) {
|
||||
|
||||
Reference in New Issue
Block a user