Skip to content
This repository was archived by the owner on Oct 13, 2023. It is now read-only.

Commit 40ccedd

Browse files
authored
Merge pull request moby#42785 from sanchayanghosh/42753-fix-host.internal
Fixed docker.internal.gateway not displaying properly on live restore
2 parents 58e6878 + 894230b commit 40ccedd

File tree

1 file changed

+19
-11
lines changed

1 file changed

+19
-11
lines changed

daemon/daemon_unix.go

+19-11
Original file line numberDiff line numberDiff line change
@@ -869,6 +869,7 @@ func (daemon *Daemon) initNetworkController(config *config.Config, activeSandbox
869869

870870
if len(activeSandboxes) > 0 {
871871
logrus.Info("There are old running containers, the network config will not take affect")
872+
setHostGatewayIP(daemon.configStore, controller)
872873
return controller, nil
873874
}
874875

@@ -906,19 +907,26 @@ func (daemon *Daemon) initNetworkController(config *config.Config, activeSandbox
906907
}
907908

908909
// Set HostGatewayIP to the default bridge's IP if it is empty
909-
if daemon.configStore.HostGatewayIP == nil && controller != nil {
910-
if n, err := controller.NetworkByName("bridge"); err == nil {
911-
v4Info, v6Info := n.Info().IpamInfo()
912-
var gateway net.IP
913-
if len(v4Info) > 0 {
914-
gateway = v4Info[0].Gateway.IP
915-
} else if len(v6Info) > 0 {
916-
gateway = v6Info[0].Gateway.IP
917-
}
918-
daemon.configStore.HostGatewayIP = gateway
910+
setHostGatewayIP(daemon.configStore, controller)
911+
912+
return controller, nil
913+
}
914+
915+
// setHostGatewayIP sets cfg.HostGatewayIP to the default bridge's IP if it is empty.
916+
func setHostGatewayIP(config *config.Config, controller libnetwork.NetworkController) {
917+
if config.HostGatewayIP != nil {
918+
return
919+
}
920+
if n, err := controller.NetworkByName("bridge"); err == nil {
921+
v4Info, v6Info := n.Info().IpamInfo()
922+
var gateway net.IP
923+
if len(v4Info) > 0 {
924+
gateway = v4Info[0].Gateway.IP
925+
} else if len(v6Info) > 0 {
926+
gateway = v6Info[0].Gateway.IP
919927
}
928+
config.HostGatewayIP = gateway
920929
}
921-
return controller, nil
922930
}
923931

924932
func driverOptions(config *config.Config) nwconfig.Option {

0 commit comments

Comments
 (0)