{"record":{"id":"309f0924a4c5455e","repo":"docker/cli","slug":"no-name-set-for-network","errorCode":null,"errorMessage":"no name set for network","messagePattern":"no name set for network","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cli/command/container/opts.go","lineNumber":861,"sourceCode":"\t\t}\n\t}\n\tif copts.ipv6Address != nil {\n\t\tif ipv6, ok := netip.AddrFromSlice(copts.ipv6Address.To16()); ok {\n\t\t\tn.IPv6Address = ipv6\n\t\t}\n\t}\n\tif copts.macAddress != \"\" {\n\t\tn.MacAddress = copts.macAddress\n\t}\n\tif copts.linkLocalIPs.Len() > 0 {\n\t\tn.LinkLocalIPs = toNetipAddrSlice(copts.linkLocalIPs.GetSlice())\n\t}\n\treturn nil\n}\n\nfunc parseNetworkAttachmentOpt(ep opts.NetworkAttachmentOpts) (*network.EndpointSettings, error) {\n\tif strings.TrimSpace(ep.Target) == \"\" {\n\t\treturn nil, errors.New(\"no name set for network\")\n\t}\n\tif !container.NetworkMode(ep.Target).IsUserDefined() {\n\t\tif len(ep.Aliases) > 0 {\n\t\t\treturn nil, errors.New(\"network-scoped aliases are only supported for user-defined networks\")\n\t\t}\n\t\tif len(ep.Links) > 0 {\n\t\t\treturn nil, errors.New(\"links are only supported for user-defined networks\")\n\t\t}\n\t}\n\n\tepConfig := &network.EndpointSettings{\n\t\tGwPriority: ep.GwPriority,\n\t}\n\tepConfig.Aliases = append(epConfig.Aliases, ep.Aliases...)\n\tif len(ep.DriverOpts) > 0 {\n\t\tepConfig.DriverOpts = make(map[string]string)\n\t\tepConfig.DriverOpts = ep.DriverOpts\n\t}","sourceCodeStart":843,"sourceCodeEnd":879,"githubUrl":"https://github.com/docker/cli/blob/4f84911bfe8811e9b028e4b1fee8e7510be79387/cli/command/container/opts.go#L843-L879","documentation":"Thrown by parseNetworkAttachmentOpt when a network attachment entry has a blank Target after trimming whitespace. The Target field is the network name (or mode) the container attaches to; an empty value means the --network argument resolved to nothing parseable. This is a defensive guard before dereferencing the network mode downstream.","triggerScenarios":"Passing `--network=` (empty value) or `--network \" \"` (whitespace). Also reachable via programmatic calls that build a NetworkAttachmentOpts with an empty Target, or a malformed comma/space separated --network list producing an empty element (e.g. `--network mynet,,other`).","commonSituations":"Shell variable expansion yielding an empty string: `docker run --network \"$NET\"` when NET is unset. Compose/network config templates with an unfilled placeholder. Scripts splitting on a delimiter producing empty tokens.","solutions":["Verify the --network value is non-empty: echo it before running docker, or guard with a shell default `--network \"${NET:?NET must be set}\"`.","Remove stray empty tokens from comma/space-separated network lists.","If building NetworkAttachmentOpts in Go, set Target to a real network name before calling parseNetworkAttachmentOpt."],"exampleFix":"// before\nNET=\"\"\ndocker run --network \"$NET\" alpine\n\n// after\nNET=\"mynet\"\ndocker run --network \"$NET\" alpine","handlingStrategy":"validation","validationCode":"func validNetworkTarget(target string) error {\n    if strings.TrimSpace(target) == \"\" {\n        return errors.New(\"no name set for network\")\n    }\n    return nil\n}\n\n// before invoking docker run / parseNetworkAttachmentOpt:\nfor _, n := range networks {\n    if err := validNetworkTarget(n); err != nil {\n        return err\n    }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always default --network to a concrete value: ${NET:-mynet} or ${NET:?required}.","Strip empty tokens when splitting comma/space-separated network lists: filter `len(s)>0`.","In Go code, assert Target is non-empty before constructing NetworkAttachmentOpts."],"tags":["network","validation","empty-value","container"],"backgroundTag":null,"analyzedSha":"4f84911bfe8811e9b028e4b1fee8e7510be79387","analyzedAt":"2026-08-07T12:15:29.814Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}