{"record":{"id":"6e54ccf5021d9f9c","repo":"docker/cli","slug":"failed-to-create-network-s-w","errorCode":null,"errorMessage":"failed to create network %s: %w","messagePattern":"failed to create network (.+?): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cli/command/stack/deploy_composefile.go","lineNumber":196,"sourceCode":"\t}\n\n\texistingNetworkMap := make(map[string]network.Summary)\n\tfor _, nw := range existingNetworks.Items {\n\t\texistingNetworkMap[nw.Name] = nw\n\t}\n\n\tfor name, createOpts := range networks {\n\t\tif _, exists := existingNetworkMap[name]; exists {\n\t\t\tcontinue\n\t\t}\n\n\t\tif createOpts.Driver == \"\" {\n\t\t\tcreateOpts.Driver = defaultNetworkDriver\n\t\t}\n\n\t\t_, _ = fmt.Fprintln(dockerCLI.Out(), \"Creating network\", name)\n\t\tif _, err := apiClient.NetworkCreate(ctx, name, createOpts); err != nil {\n\t\t\treturn fmt.Errorf(\"failed to create network %s: %w\", name, err)\n\t\t}\n\t}\n\treturn nil\n}\n\nfunc deployServices(ctx context.Context, dockerCLI command.Cli, services map[string]swarm.ServiceSpec, namespace convert.Namespace, sendAuth bool, resolveImage string) ([]string, error) {\n\tapiClient := dockerCLI.Client()\n\tout := dockerCLI.Out()\n\n\texistingServices, err := getStackServices(ctx, apiClient, namespace.Name())\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\texistingServiceMap := make(map[string]swarm.Service)\n\tfor _, svc := range existingServices.Items {\n\t\texistingServiceMap[svc.Spec.Name] = svc\n\t}","sourceCodeStart":178,"sourceCodeEnd":214,"githubUrl":"https://github.com/docker/cli/blob/4f84911bfe8811e9b028e4b1fee8e7510be79387/cli/command/stack/deploy_composefile.go#L178-L214","documentation":"Raised by createNetworks when NetworkCreate fails for a stack-managed (non-external) network. Stack deploy creates overlay networks named <stack>_<network>; the wrapped %w carries the daemon error (driver unavailable, name collision, label error).","triggerScenarios":"Deploying a stack where a network is not marked external (so createNetworks tries NetworkCreate at deploy_composefile.go:195) and the daemon rejects the creation. Triggers when the overlay driver is unavailable, a same-named network already exists outside the stack, or network option conversion produced invalid params.","commonSituations":"Deploying on a node that is not a swarm manager or has no overlay driver; a leftover network from a previous stack with the same name but no stack label; invalid driver options in compose; overlapping CIDRs across networks.","solutions":["Confirm the node is a swarm manager and overlay networking is available.","Read the wrapped error; a name collision means removing the stray network: `docker network rm <name>`.","Check for CIDR overlaps with existing networks and adjust subnet config in compose.","Validate driver/options in compose for the network that failed."],"exampleFix":"// before: CIDR overlap with existing network\nnetworks:\n  front:\n    ipam:\n      config:\n        - subnet: 172.16.0.0/16  # collides\n// after: use a unique subnet\nnetworks:\n  front:\n    ipam:\n      config:\n        - subnet: 10.20.0.0/16","handlingStrategy":"validation","validationCode":"// Pre-check: manager status and network name collisions before deploy\ninfo, err := c.Info(ctx, client.InfoOptions{})\nif err != nil { return err }\nif !info.Info.Swarm.ControlAvailable { return errors.New(\"not a swarm manager\") }\n// Check for a stray network with the target name lacking the stack label\nfor name := range stackNetworks {\n    if res, err := c.NetworkInspect(ctx, name, client.NetworkInspectOptions{}); err == nil {\n        if _, ok := res.Network.Labels[\"com.docker.stack.namespace\"]; !ok {\n            return fmt.Errorf(\"network %q exists outside any stack; remove or rename\", name)\n        }\n    }\n}","typeGuard":null,"tryCatchPattern":"if err := stackDeploy(ctx, cli, opts, cfg); err != nil {\n    if strings.Contains(err.Error(), \"failed to create network\") {\n        // inspect wrapped error; remove stray network and retry\n    }\n    return err\n}","preventionTips":["Confirm the node is a swarm manager with overlay support.","Avoid CIDR overlaps; plan subnets per stack.","Remove orphaned networks from failed deploys."],"tags":["docker","stack","network","swarm","create"],"backgroundTag":null,"analyzedSha":"4f84911bfe8811e9b028e4b1fee8e7510be79387","analyzedAt":"2026-08-07T12:15:29.814Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}