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,14 +163,16 @@ func (s *composeService) removeNetwork(ctx context.Context, name string, w progr
|
|||
|
||||
var removed int
|
||||
for _, net := range networks {
|
||||
if err := s.apiClient().NetworkRemove(ctx, net.ID); err != nil {
|
||||
if errdefs.IsNotFound(err) {
|
||||
continue
|
||||
if net.Name == name {
|
||||
if err := s.apiClient().NetworkRemove(ctx, net.ID); err != nil {
|
||||
if errdefs.IsNotFound(err) {
|
||||
continue
|
||||
}
|
||||
w.Event(progress.ErrorEvent(eventName))
|
||||
return errors.Wrapf(err, fmt.Sprintf("failed to remove network %s", name))
|
||||
}
|
||||
w.Event(progress.ErrorEvent(eventName))
|
||||
return errors.Wrapf(err, fmt.Sprintf("failed to remove network %s", name))
|
||||
removed++
|
||||
}
|
||||
removed++
|
||||
}
|
||||
|
||||
if removed == 0 {
|
||||
|
|
Loading…
Reference in New Issue