Merge pull request #9640 from glours/fix-close-network-name-issue

Fix issue with close networks name on up and down command
This commit is contained in:
Guillaume Lours 2022-07-13 10:46:13 +02:00 committed by GitHub
commit 9fdd7d81b3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 7 deletions

View File

@ -1041,7 +1041,14 @@ func (s *composeService) ensureNetwork(ctx context.Context, n types.NetworkConfi
if err != nil {
return err
}
if len(networks) == 0 {
networkNotFound := true
for _, net := range networks {
if net.Name == n.Name {
networkNotFound = false
break
}
}
if networkNotFound {
if n.External.External {
if n.Driver == "overlay" {
// Swarm nodes do not register overlay networks that were

View File

@ -163,6 +163,7 @@ func (s *composeService) removeNetwork(ctx context.Context, name string, w progr
var removed int
for _, net := range networks {
if net.Name == name {
if err := s.apiClient().NetworkRemove(ctx, net.ID); err != nil {
if errdefs.IsNotFound(err) {
continue
@ -172,6 +173,7 @@ func (s *composeService) removeNetwork(ctx context.Context, name string, w progr
}
removed++
}
}
if removed == 0 {
// in practice, it's extremely unlikely for this to ever occur, as it'd