mirror of https://github.com/docker/compose.git
check the exact network's name before creating or stopping it
NetworkList API doesn't return the extact name match, so we can retrieve more than one network with a request Signed-off-by: Guillaume Lours <guillaume.lours@docker.com>
This commit is contained in:
parent
5bc4016e70
commit
50aa9750ee
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue