From 123f0bfd9894be11cb2da401dad513fd7373d41c Mon Sep 17 00:00:00 2001 From: Madhu Venugopal Date: Thu, 25 May 2017 19:50:08 -0700 Subject: [PATCH] With the introduction of node-local network support, docker services can be attached to special networks such as host and bridge. This fix brings in the required changes to make sure the stack file accepts these networks as well. Signed-off-by: Madhu Venugopal --- cli/command/stack/deploy_composefile.go | 5 +++-- cli/compose/convert/service.go | 19 +++++++++++-------- 2 files changed, 14 insertions(+), 10 deletions(-) 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))