Fixed docker.internal.gateway not displaying properly on live restore
Also includes review suggestions in daemon.initNetworkController():
update godoc for setHostGatewayIP()
change setHostGatewayIP() to get config, instead of daemon
remove redundant nil check for controller
@@ -869,6 +869,7 @@ func (daemon *Daemon) initNetworkController(config *config.Config, activeSandbox
if len(activeSandboxes) > 0 {
logrus.Info("There are old running containers, the network config will not take affect")
+ setHostGatewayIP(daemon.configStore, controller)
return controller, nil
}
@@ -906,7 +907,16 @@ func (daemon *Daemon) initNetworkController(config *config.Config, activeSandbox
}
// Set HostGatewayIP to the default bridge's IP if it is empty
- if daemon.configStore.HostGatewayIP == nil && controller != nil {
+ setHostGatewayIP(daemon.configStore, controller)
+
+ return controller, nil
+}
+
+// setHostGatewayIP sets cfg.HostGatewayIP to the default bridge's IP if it is empty.
+func setHostGatewayIP(config *config.Config, controller libnetwork.NetworkController) {
+ if config.HostGatewayIP != nil {
+ return
+ }
if n, err := controller.NetworkByName("bridge"); err == nil {
v4Info, v6Info := n.Info().IpamInfo()
var gateway net.IP
@@ -915,11 +925,9 @@ func (daemon *Daemon) initNetworkController(config *config.Config, activeSandbox
} else if len(v6Info) > 0 {
gateway = v6Info[0].Gateway.IP
}
- daemon.configStore.HostGatewayIP = gateway
+ config.HostGatewayIP = gateway
}
}
- return controller, nil
-}
func driverOptions(config *config.Config) []nwconfig.Option {
bridgeConfig := options.Generic{
