mirror of https://github.com/docker/cli.git
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:
parent
11e7d35f9c
commit
123f0bfd98
|
@ -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")
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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{
|
||||
netAttachConfig := swarm.NetworkAttachmentConfig{
|
||||
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))
|
||||
|
|
Loading…
Reference in New Issue