{"id":"f07dd5ae60e49a23","repo":"docker/cli","slug":"every-ip-range-or-gateway-must-have-a-correspondin","errorCode":null,"errorMessage":"every ip-range or gateway must have a corresponding subnet","messagePattern":"every ip-range or gateway must have a corresponding subnet","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cli/command/network/create.go","lineNumber":141,"sourceCode":"\t\tLabels:     opts.ConvertKVStringsToMap(options.labels.GetSlice()),\n\t})\n\tif err != nil {\n\t\treturn err\n\t}\n\t_, _ = fmt.Fprintln(output, resp.ID)\n\treturn nil\n}\n\n// Consolidates the ipam configuration as a group from different related configurations\n// user can configure network with multiple non-overlapping subnets and hence it is\n// possible to correlate the various related parameters and consolidate them.\n// createIPAMConfig consolidates subnets, ip-ranges, gateways and auxiliary addresses into\n// structured ipam data.\n//\n//nolint:gocyclo\nfunc createIPAMConfig(options ipamOptions) (*network.IPAM, error) {\n\tif len(options.subnets) < len(options.ipRanges) || len(options.subnets) < len(options.gateways) {\n\t\treturn nil, errors.New(\"every ip-range or gateway must have a corresponding subnet\")\n\t}\n\tiData := map[string]*network.IPAMConfig{}\n\n\t// Populate non-overlapping subnets into consolidation map\n\tfor _, s := range options.subnets {\n\t\tfor k := range iData {\n\t\t\tok1, err := subnetMatches(s, k)\n\t\t\tif err != nil {\n\t\t\t\treturn nil, err\n\t\t\t}\n\t\t\tok2, err := subnetMatches(k, s)\n\t\t\tif err != nil {\n\t\t\t\treturn nil, err\n\t\t\t}\n\t\t\tif ok1 || ok2 {\n\t\t\t\treturn nil, errors.New(\"multiple overlapping subnet configuration is not supported\")\n\t\t\t}\n\t\t}","sourceCodeStart":123,"sourceCodeEnd":159,"githubUrl":"https://github.com/docker/cli/blob/e9452d6e785f6e365712b9d71bd7517591773c86/cli/command/network/create.go#L123-L159","documentation":"Raised by createIPAMConfig in `docker network create` when the count of --ip-range or --gateway flags exceeds the count of --subnet flags. Each ip-range and gateway must be nested inside a declared subnet, so the CLI rejects the configuration up front before calling the NetworkCreate API.","triggerScenarios":"Running `docker network create` with len(ipRanges) > len(subnets) or len(gateways) > len(subnets), e.g. `docker network create --gateway 10.0.0.1 mynet` with no --subnet, or two --ip-range flags but one --subnet.","commonSituations":"Scripts that template out gateway/ip-range flags but forget the subnet; copy-pasted compose-to-CLI translations; adding an IPv6 gateway without adding the matching IPv6 subnet.","solutions":["Add a --subnet flag for every --ip-range and --gateway you pass (e.g. --subnet 10.0.0.0/16 --gateway 10.0.0.1)","Remove stray --gateway/--ip-range flags if you want Docker's default IPAM allocation","For dual-stack networks, declare both the IPv4 and IPv6 subnets before their respective gateways"],"exampleFix":"# before\ndocker network create --gateway 10.0.0.1 mynet\n# after\ndocker network create --subnet 10.0.0.0/16 --gateway 10.0.0.1 mynet","handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":["docker","network","ipam","cli-validation"],"analyzedSha":"e9452d6e785f6e365712b9d71bd7517591773c86","analyzedAt":"2026-08-01T07:09:22.474Z","schemaVersion":2}