{"record":{"id":"f99c141668dbcf9e","repo":"docker/cli","slug":"undefined-network-q","errorCode":null,"errorMessage":"undefined network %q","messagePattern":"undefined network %q","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cli/compose/convert/service.go","lineNumber":213,"sourceCode":"}\n\nfunc convertServiceNetworks(\n\tnetworks map[string]*composetypes.ServiceNetworkConfig,\n\tnetworkConfigs networkMap,\n\tnamespace Namespace,\n\tname string,\n) ([]swarm.NetworkAttachmentConfig, error) {\n\tif len(networks) == 0 {\n\t\tnetworks = map[string]*composetypes.ServiceNetworkConfig{\n\t\t\tdefaultNetwork: {},\n\t\t}\n\t}\n\n\tnets := make([]swarm.NetworkAttachmentConfig, 0, len(networks))\n\tfor networkName, nw := range networks {\n\t\tnetworkConfig, ok := networkConfigs[networkName]\n\t\tif !ok && networkName != defaultNetwork {\n\t\t\treturn nil, fmt.Errorf(\"undefined network %q\", networkName)\n\t\t}\n\t\tvar aliases []string\n\t\tvar driverOpts map[string]string\n\t\tif nw != nil {\n\t\t\taliases = nw.Aliases\n\t\t\tdriverOpts = nw.DriverOpts\n\t\t}\n\t\ttarget := namespace.Scope(networkName)\n\t\tif networkConfig.Name != \"\" {\n\t\t\ttarget = networkConfig.Name\n\t\t}\n\t\tnetAttachConfig := swarm.NetworkAttachmentConfig{\n\t\t\tTarget:     target,\n\t\t\tAliases:    aliases,\n\t\t\tDriverOpts: driverOpts,\n\t\t}\n\t\t// Only add default aliases to user defined networks. Other networks do\n\t\t// not support aliases.","sourceCodeStart":195,"sourceCodeEnd":231,"githubUrl":"https://github.com/docker/cli/blob/4f84911bfe8811e9b028e4b1fee8e7510be79387/cli/compose/convert/service.go#L195-L231","documentation":"Returned by convertServiceNetworks when a service lists a network that is neither defined in the top-level networks map nor the implicit 'default' network (service.go:210-214). Swarm conversion refuses to attach a service to a network it cannot resolve.","triggerScenarios":"A service's `networks:` references a name that has no matching entry in the top-level `networks:` block and is not 'default'. Reached at service.go:212 when networkConfigs[networkName] is absent and networkName != defaultNetwork.","commonSituations":"Renamed a network in one section only; copy-pasted a service that uses a network never added to the file; merged two compose files where the network definition lives in a file that wasn't included.","solutions":["Add the referenced network to the top-level `networks:` block.","If the network already exists in Docker, declare it with `external: true`.","Fix the typo in the service's network name to match a defined network."],"exampleFix":"// before\nservices:\n  web:\n    image: nginx\n    networks: [frontnet]\n// after\nservices:\n  web:\n    image: nginx\n    networks: [frontnet]\nnetworks:\n  frontnet:","handlingStrategy":"validation","validationCode":"// Ensure every network referenced by a service is declared (or is 'default').\nfunc validateNetworks(cfg *composetypes.Config) error {\n    for _, svc := range cfg.Services {\n        for name := range svc.Networks {\n            if name == \"default\" {\n                continue\n            }\n            if _, ok := cfg.Networks[name]; !ok {\n                return fmt.Errorf(\"undefined network %q\", name)\n            }\n        }\n    }\n    return nil\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Declare each referenced network in the top-level networks block.","Use external: true for networks that already exist in Docker.","Lint with docker compose config to catch dangling network references."],"tags":["compose","convert","networks","swarm","undefined"],"backgroundTag":null,"analyzedSha":"4f84911bfe8811e9b028e4b1fee8e7510be79387","analyzedAt":"2026-08-07T12:15:29.814Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}