fixed incorrect assumption on --bridge=none treated as disable network
| ... | ... |
@@ -469,7 +469,7 @@ func (container *Container) buildJoinOptions() ([]libnetwork.EndpointOption, err |
| 469 | 469 |
logrus.Error(err) |
| 470 | 470 |
} |
| 471 | 471 |
|
| 472 |
- if c != nil && !container.daemon.config.DisableNetwork && container.hostConfig.NetworkMode.IsPrivate() {
|
|
| 472 |
+ if c != nil && !container.daemon.config.DisableBridge && container.hostConfig.NetworkMode.IsPrivate() {
|
|
| 473 | 473 |
logrus.Debugf("Update /etc/hosts of %s for alias %s with ip %s", c.ID, ref.Name, container.NetworkSettings.IPAddress)
|
| 474 | 474 |
joinOptions = append(joinOptions, libnetwork.JoinOptionParentUpdate(c.NetworkSettings.EndpointID, ref.Name, container.NetworkSettings.IPAddress)) |
| 475 | 475 |
if c.NetworkSettings.EndpointID != "" {
|
| ... | ... |
@@ -773,6 +773,11 @@ func (container *Container) secondaryNetworkRequired(primaryNetworkType string) |
| 773 | 773 |
case "bridge", "none", "host", "container": |
| 774 | 774 |
return false |
| 775 | 775 |
} |
| 776 |
+ |
|
| 777 |
+ if container.daemon.config.DisableBridge {
|
|
| 778 |
+ return false |
|
| 779 |
+ } |
|
| 780 |
+ |
|
| 776 | 781 |
if container.Config.ExposedPorts != nil && len(container.Config.ExposedPorts) > 0 {
|
| 777 | 782 |
return true |
| 778 | 783 |
} |
| ... | ... |
@@ -803,6 +808,11 @@ func (container *Container) AllocateNetwork() error {
|
| 803 | 803 |
return fmt.Errorf("conflicting options: publishing a service and network mode")
|
| 804 | 804 |
} |
| 805 | 805 |
|
| 806 |
+ if runconfig.NetworkMode(networkDriver).IsBridge() && container.daemon.config.DisableBridge {
|
|
| 807 |
+ container.Config.NetworkDisabled = true |
|
| 808 |
+ return nil |
|
| 809 |
+ } |
|
| 810 |
+ |
|
| 806 | 811 |
if service == "" {
|
| 807 | 812 |
// dot character "." has a special meaning to support SERVICE[.NETWORK] format. |
| 808 | 813 |
// For backward compatiblity, replacing "." with "-", instead of failing |
| ... | ... |
@@ -897,10 +907,6 @@ func (container *Container) initializeNetworking() error {
|
| 897 | 897 |
return nil |
| 898 | 898 |
} |
| 899 | 899 |
|
| 900 |
- if container.daemon.config.DisableNetwork {
|
|
| 901 |
- container.Config.NetworkDisabled = true |
|
| 902 |
- } |
|
| 903 |
- |
|
| 904 | 900 |
if container.hostConfig.NetworkMode.IsHost() {
|
| 905 | 901 |
container.Config.Hostname, err = os.Hostname() |
| 906 | 902 |
if err != nil {
|
| ... | ... |
@@ -999,7 +1005,7 @@ func (container *Container) getNetworkedContainer() (*Container, error) {
|
| 999 | 999 |
} |
| 1000 | 1000 |
|
| 1001 | 1001 |
func (container *Container) ReleaseNetwork() {
|
| 1002 |
- if container.hostConfig.NetworkMode.IsContainer() || container.daemon.config.DisableNetwork {
|
|
| 1002 |
+ if container.hostConfig.NetworkMode.IsContainer() || container.Config.NetworkDisabled {
|
|
| 1003 | 1003 |
return |
| 1004 | 1004 |
} |
| 1005 | 1005 |
|
| ... | ... |
@@ -561,7 +561,7 @@ func NewDaemon(config *Config, registryService *registry.Service) (daemon *Daemo |
| 561 | 561 |
} |
| 562 | 562 |
|
| 563 | 563 |
// Do we have a disabled network? |
| 564 |
- config.DisableNetwork = isNetworkDisabled(config) |
|
| 564 |
+ config.DisableBridge = isBridgeNetworkDisabled(config) |
|
| 565 | 565 |
|
| 566 | 566 |
// Check that the system is supported and we have sufficient privileges |
| 567 | 567 |
if err := checkSystem(); err != nil {
|
| ... | ... |
@@ -684,11 +684,9 @@ func NewDaemon(config *Config, registryService *registry.Service) (daemon *Daemo |
| 684 | 684 |
return nil, fmt.Errorf("Couldn't create Tag store: %s", err)
|
| 685 | 685 |
} |
| 686 | 686 |
|
| 687 |
- if !config.DisableNetwork {
|
|
| 688 |
- d.netController, err = initNetworkController(config) |
|
| 689 |
- if err != nil {
|
|
| 690 |
- return nil, fmt.Errorf("Error initializing network controller: %v", err)
|
|
| 691 |
- } |
|
| 687 |
+ d.netController, err = initNetworkController(config) |
|
| 688 |
+ if err != nil {
|
|
| 689 |
+ return nil, fmt.Errorf("Error initializing network controller: %v", err)
|
|
| 692 | 690 |
} |
| 693 | 691 |
|
| 694 | 692 |
graphdbPath := filepath.Join(config.Root, "linkgraph.db") |
| ... | ... |
@@ -268,7 +268,7 @@ func configureSysInit(config *Config) (string, error) {
|
| 268 | 268 |
return sysInitPath, nil |
| 269 | 269 |
} |
| 270 | 270 |
|
| 271 |
-func isNetworkDisabled(config *Config) bool {
|
|
| 271 |
+func isBridgeNetworkDisabled(config *Config) bool {
|
|
| 272 | 272 |
return config.Bridge.Iface == disableNetworkBridge |
| 273 | 273 |
} |
| 274 | 274 |
|
| ... | ... |
@@ -336,12 +336,22 @@ func initNetworkController(config *Config) (libnetwork.NetworkController, error) |
| 336 | 336 |
return nil, fmt.Errorf("Error creating default \"host\" network: %v", err)
|
| 337 | 337 |
} |
| 338 | 338 |
|
| 339 |
- // Initialize default driver "bridge" |
|
| 339 |
+ if !config.DisableBridge {
|
|
| 340 |
+ // Initialize default driver "bridge" |
|
| 341 |
+ if err := initBridgeDriver(controller, config); err != nil {
|
|
| 342 |
+ return nil, err |
|
| 343 |
+ } |
|
| 344 |
+ } |
|
| 345 |
+ |
|
| 346 |
+ return controller, nil |
|
| 347 |
+} |
|
| 348 |
+ |
|
| 349 |
+func initBridgeDriver(controller libnetwork.NetworkController, config *Config) error {
|
|
| 340 | 350 |
option := options.Generic{
|
| 341 | 351 |
"EnableIPForwarding": config.Bridge.EnableIPForward} |
| 342 | 352 |
|
| 343 | 353 |
if err := controller.ConfigureNetworkDriver("bridge", options.Generic{netlabel.GenericData: option}); err != nil {
|
| 344 |
- return nil, fmt.Errorf("Error initializing bridge driver: %v", err)
|
|
| 354 |
+ return fmt.Errorf("Error initializing bridge driver: %v", err)
|
|
| 345 | 355 |
} |
| 346 | 356 |
|
| 347 | 357 |
netOption := options.Generic{
|
| ... | ... |
@@ -356,7 +366,7 @@ func initNetworkController(config *Config) (libnetwork.NetworkController, error) |
| 356 | 356 |
if config.Bridge.IP != "" {
|
| 357 | 357 |
ip, bipNet, err := net.ParseCIDR(config.Bridge.IP) |
| 358 | 358 |
if err != nil {
|
| 359 |
- return nil, err |
|
| 359 |
+ return err |
|
| 360 | 360 |
} |
| 361 | 361 |
|
| 362 | 362 |
bipNet.IP = ip |
| ... | ... |
@@ -366,7 +376,7 @@ func initNetworkController(config *Config) (libnetwork.NetworkController, error) |
| 366 | 366 |
if config.Bridge.FixedCIDR != "" {
|
| 367 | 367 |
_, fCIDR, err := net.ParseCIDR(config.Bridge.FixedCIDR) |
| 368 | 368 |
if err != nil {
|
| 369 |
- return nil, err |
|
| 369 |
+ return err |
|
| 370 | 370 |
} |
| 371 | 371 |
|
| 372 | 372 |
netOption["FixedCIDR"] = fCIDR |
| ... | ... |
@@ -375,7 +385,7 @@ func initNetworkController(config *Config) (libnetwork.NetworkController, error) |
| 375 | 375 |
if config.Bridge.FixedCIDRv6 != "" {
|
| 376 | 376 |
_, fCIDRv6, err := net.ParseCIDR(config.Bridge.FixedCIDRv6) |
| 377 | 377 |
if err != nil {
|
| 378 |
- return nil, err |
|
| 378 |
+ return err |
|
| 379 | 379 |
} |
| 380 | 380 |
|
| 381 | 381 |
netOption["FixedCIDRv6"] = fCIDRv6 |
| ... | ... |
@@ -395,16 +405,15 @@ func initNetworkController(config *Config) (libnetwork.NetworkController, error) |
| 395 | 395 |
} |
| 396 | 396 |
|
| 397 | 397 |
// Initialize default network on "bridge" with the same name |
| 398 |
- _, err = controller.NewNetwork("bridge", "bridge",
|
|
| 398 |
+ _, err := controller.NewNetwork("bridge", "bridge",
|
|
| 399 | 399 |
libnetwork.NetworkOptionGeneric(options.Generic{
|
| 400 | 400 |
netlabel.GenericData: netOption, |
| 401 | 401 |
netlabel.EnableIPv6: config.Bridge.EnableIPv6, |
| 402 | 402 |
})) |
| 403 | 403 |
if err != nil {
|
| 404 |
- return nil, fmt.Errorf("Error creating default \"bridge\" network: %v", err)
|
|
| 404 |
+ return fmt.Errorf("Error creating default \"bridge\" network: %v", err)
|
|
| 405 | 405 |
} |
| 406 |
- |
|
| 407 |
- return controller, nil |
|
| 406 |
+ return nil |
|
| 408 | 407 |
} |
| 409 | 408 |
|
| 410 | 409 |
// setupInitLayer populates a directory with mountpoints suitable |
| ... | ... |
@@ -1324,7 +1324,17 @@ func (s *DockerDaemonSuite) TestRunContainerWithBridgeNone(c *check.C) {
|
| 1324 | 1324 |
out, err := s.d.Cmd("run", "--rm", "busybox", "ip", "l")
|
| 1325 | 1325 |
c.Assert(err, check.IsNil, check.Commentf("Output: %s", out))
|
| 1326 | 1326 |
c.Assert(strings.Contains(out, "eth0"), check.Equals, false, |
| 1327 |
- check.Commentf("There shouldn't be eth0 in container when network is disabled: %s", out))
|
|
| 1327 |
+ check.Commentf("There shouldn't be eth0 in container in default(bridge) mode when bridge network is disabled: %s", out))
|
|
| 1328 |
+ |
|
| 1329 |
+ out, err = s.d.Cmd("run", "--rm", "--net=bridge", "busybox", "ip", "l")
|
|
| 1330 |
+ c.Assert(err, check.IsNil, check.Commentf("Output: %s", out))
|
|
| 1331 |
+ c.Assert(strings.Contains(out, "eth0"), check.Equals, false, |
|
| 1332 |
+ check.Commentf("There shouldn't be eth0 in container in bridge mode when bridge network is disabled: %s", out))
|
|
| 1333 |
+ |
|
| 1334 |
+ out, err = s.d.Cmd("run", "--rm", "--net=host", "busybox", "ip", "l")
|
|
| 1335 |
+ c.Assert(err, check.IsNil, check.Commentf("Output: %s", out))
|
|
| 1336 |
+ c.Assert(strings.Contains(out, "eth0"), check.Equals, true, |
|
| 1337 |
+ check.Commentf("There should be eth0 in container when --net=host when bridge network is disabled: %s", out))
|
|
| 1328 | 1338 |
} |
| 1329 | 1339 |
|
| 1330 | 1340 |
func (s *DockerDaemonSuite) TestDaemonRestartWithContainerRunning(t *check.C) {
|