diff --git a/daemon/daemon_windows.go b/daemon/daemon_windows.go index e283d76f5e..15f160761e 100644 --- a/daemon/daemon_windows.go +++ b/daemon/daemon_windows.go @@ -20,6 +20,7 @@ import ( "github.com/docker/docker/runconfig" "github.com/docker/libnetwork" nwconfig "github.com/docker/libnetwork/config" + "github.com/docker/libnetwork/datastore" winlibnetwork "github.com/docker/libnetwork/drivers/windows" "github.com/docker/libnetwork/netlabel" "github.com/docker/libnetwork/options" @@ -261,9 +262,12 @@ func (daemon *Daemon) initNetworkController(config *Config, activeSandboxes map[ } if !found { - err = v.Delete() - if err != nil { - return nil, err + // global networks should not be deleted by local HNS + if v.Info().Scope() != datastore.GlobalScope { + err = v.Delete() + if err != nil { + logrus.Errorf("Error occurred when removing network %v", err) + } } } } @@ -300,6 +304,10 @@ func (daemon *Daemon) initNetworkController(config *Config, activeSandboxes map[ controller.WalkNetworks(s) if n != nil { + // global networks should not be deleted by local HNS + if n.Info().Scope() == datastore.GlobalScope { + continue + } v.Name = n.Name() // This will not cause network delete from HNS as the network // is not yet populated in the libnetwork windows driver diff --git a/daemon/start_windows.go b/daemon/start_windows.go index c792d35809..faa7575224 100644 --- a/daemon/start_windows.go +++ b/daemon/start_windows.go @@ -62,6 +62,7 @@ func (daemon *Daemon) getLibcontainerdCreateOptions(container *container.Contain // Get endpoints for the libnetwork allocated networks to the container var epList []string AllowUnqualifiedDNSQuery := false + gwHNSID := "" if container.NetworkSettings != nil { for n := range container.NetworkSettings.Networks { sn, err := daemon.FindNetwork(n) @@ -78,6 +79,14 @@ func (daemon *Daemon) getLibcontainerdCreateOptions(container *container.Contain if err != nil { continue } + + if data["GW_INFO"] != nil { + gwInfo := data["GW_INFO"].(map[string]interface{}) + if gwInfo["hnsid"] != nil { + gwHNSID = gwInfo["hnsid"].(string) + } + } + if data["hnsid"] != nil { epList = append(epList, data["hnsid"].(string)) } @@ -88,6 +97,10 @@ func (daemon *Daemon) getLibcontainerdCreateOptions(container *container.Contain } } + if gwHNSID != "" { + epList = append(epList, gwHNSID) + } + // Read and add credentials from the security options if a credential spec has been provided. if container.HostConfig.SecurityOpt != nil { for _, sOpt := range container.HostConfig.SecurityOpt {