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 <madhu@docker.com>
This commit is contained in:
Madhu Venugopal 2017-05-25 19:50:08 -07:00
parent 11e7d35f9c
commit 123f0bfd98
2 changed files with 14 additions and 10 deletions

View File

@ -13,6 +13,7 @@ import (
"github.com/docker/cli/cli/compose/loader" "github.com/docker/cli/cli/compose/loader"
composetypes "github.com/docker/cli/cli/compose/types" composetypes "github.com/docker/cli/cli/compose/types"
"github.com/docker/docker/api/types" "github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/container"
"github.com/docker/docker/api/types/swarm" "github.com/docker/docker/api/types/swarm"
apiclient "github.com/docker/docker/client" apiclient "github.com/docker/docker/client"
dockerclient "github.com/docker/docker/client" dockerclient "github.com/docker/docker/client"
@ -177,11 +178,11 @@ func validateExternalNetworks(
network, err := client.NetworkInspect(ctx, networkName, false) network, err := client.NetworkInspect(ctx, networkName, false)
if err != nil { if err != nil {
if dockerclient.IsErrNetworkNotFound(err) { 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 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") 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")
} }
} }

View File

@ -214,18 +214,21 @@ func convertServiceNetworks(
if !ok && networkName != defaultNetwork { if !ok && networkName != defaultNetwork {
return nil, errors.Errorf("undefined network %q", networkName) return nil, errors.Errorf("undefined network %q", networkName)
} }
var aliases []string
if network != nil {
aliases = network.Aliases
}
target := namespace.Scope(networkName) target := namespace.Scope(networkName)
if networkConfig.External.External { if networkConfig.External.External {
target = networkConfig.External.Name target = networkConfig.External.Name
} }
nets = append(nets, swarm.NetworkAttachmentConfig{ netAttachConfig := swarm.NetworkAttachmentConfig{
Target: target, Target: target,
Aliases: append(aliases, name), }
}) 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)) sort.Sort(byNetworkTarget(nets))