Merge pull request #42785 from sanchayanghosh/42753-fix-host.internal
Fixed docker.internal.gateway not displaying properly on live restore
This commit is contained in:
commit
40ccedd61b
1 changed files with 20 additions and 12 deletions
|
@ -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,21 +907,28 @@ 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 {
|
||||
if n, err := controller.NetworkByName("bridge"); err == nil {
|
||||
v4Info, v6Info := n.Info().IpamInfo()
|
||||
var gateway net.IP
|
||||
if len(v4Info) > 0 {
|
||||
gateway = v4Info[0].Gateway.IP
|
||||
} else if len(v6Info) > 0 {
|
||||
gateway = v6Info[0].Gateway.IP
|
||||
}
|
||||
daemon.configStore.HostGatewayIP = gateway
|
||||
}
|
||||
}
|
||||
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
|
||||
if len(v4Info) > 0 {
|
||||
gateway = v4Info[0].Gateway.IP
|
||||
} else if len(v6Info) > 0 {
|
||||
gateway = v6Info[0].Gateway.IP
|
||||
}
|
||||
config.HostGatewayIP = gateway
|
||||
}
|
||||
}
|
||||
|
||||
func driverOptions(config *config.Config) nwconfig.Option {
|
||||
return nwconfig.OptionDriverConfig("bridge", options.Generic{
|
||||
netlabel.GenericData: options.Generic{
|
||||
|
|
Loading…
Add table
Reference in a new issue