diff --git a/cli/command/stack/deploy_composefile.go b/cli/command/stack/deploy_composefile.go index abe0b0ea2c..1b2ca1d6f0 100644 --- a/cli/command/stack/deploy_composefile.go +++ b/cli/command/stack/deploy_composefile.go @@ -13,6 +13,7 @@ import ( "github.com/docker/cli/cli/compose/loader" composetypes "github.com/docker/cli/cli/compose/types" "github.com/docker/docker/api/types" + "github.com/docker/docker/api/types/container" "github.com/docker/docker/api/types/swarm" apiclient "github.com/docker/docker/client" dockerclient "github.com/docker/docker/client" @@ -177,11 +178,11 @@ func validateExternalNetworks( network, err := client.NetworkInspect(ctx, networkName, false) if err != nil { if dockerclient.IsErrNetworkNotFound(err) { - return errors.Errorf("network %q is declared as external, but could not be found. You need to create the network before the stack is deployed (with overlay driver)", networkName) + return errors.Errorf("network %q is declared as external, but could not be found. You need to create a swarm-scoped network before the stack is deployed", networkName) } return err } - if network.Scope != "swarm" { + if container.NetworkMode(networkName).IsUserDefined() && network.Scope != "swarm" { return errors.Errorf("network %q is declared as external, but it is not in the right scope: %q instead of %q", networkName, network.Scope, "swarm") } } diff --git a/cli/compose/convert/service.go b/cli/compose/convert/service.go index 79c6555276..8b0dd311e0 100644 --- a/cli/compose/convert/service.go +++ b/cli/compose/convert/service.go @@ -214,18 +214,21 @@ func convertServiceNetworks( if !ok && networkName != defaultNetwork { return nil, errors.Errorf("undefined network %q", networkName) } - var aliases []string - if network != nil { - aliases = network.Aliases - } target := namespace.Scope(networkName) if networkConfig.External.External { target = networkConfig.External.Name } - nets = append(nets, swarm.NetworkAttachmentConfig{ - Target: target, - Aliases: append(aliases, name), - }) + netAttachConfig := swarm.NetworkAttachmentConfig{ + Target: target, + } + if container.NetworkMode(target).IsUserDefined() { + var aliases []string + if network != nil { + aliases = network.Aliases + } + netAttachConfig.Aliases = append(aliases, name) + } + nets = append(nets, netAttachConfig) } sort.Sort(byNetworkTarget(nets))