{"record":{"id":"41008af2d5949daa","repo":"hashicorp/nomad","slug":"port-q-not-found-check-network-block","errorCode":null,"errorMessage":"Port %q not found, check network block","messagePattern":"Port %q not found, check network block","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"drivers/docker/driver.go","lineNumber":1433,"sourceCode":"\t\t\tlogger.Debug(\"networking mode not specified; using default\")\n\t\t\thostConfig.NetworkMode = \"default\"\n\t\t}\n\t}\n\n\t// Setup port mapping and exposed ports\n\tports := newPublishedPorts(logger)\n\tswitch {\n\tcase task.Resources.Ports != nil && len(driverConfig.Ports) > 0:\n\t\t// Do not set up docker port mapping if shared alloc networking is used\n\t\tif hostConfig.NetworkMode.IsContainer() {\n\t\t\tbreak\n\t\t}\n\n\t\tfor _, port := range driverConfig.Ports {\n\t\t\tif mapping, ok := task.Resources.Ports.Get(port); ok {\n\t\t\t\tports.add(mapping.Label, mapping.HostIP, mapping.Value, mapping.To)\n\t\t\t} else {\n\t\t\t\treturn c, fmt.Errorf(\"Port %q not found, check network block\", port)\n\t\t\t}\n\t\t}\n\tcase len(task.Resources.NomadResources.Networks) > 0:\n\t\tnetwork := task.Resources.NomadResources.Networks[0]\n\n\t\tfor _, port := range network.ReservedPorts {\n\t\t\tports.addMapped(port.Label, network.IP, port.Value, driverConfig.PortMap)\n\t\t}\n\n\t\tfor _, port := range network.DynamicPorts {\n\t\t\tports.addMapped(port.Label, network.IP, port.Value, driverConfig.PortMap)\n\t\t}\n\n\tdefault:\n\t\tif len(driverConfig.PortMap) > 0 {\n\t\t\tif task.Resources.Ports != nil {\n\t\t\t\treturn c, fmt.Errorf(\"'port_map' cannot map group network ports, use 'ports' instead\")\n\t\t\t}","sourceCodeStart":1415,"sourceCodeEnd":1451,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/drivers/docker/driver.go#L1415-L1451","documentation":"When the docker driver config lists a ports array, every label must resolve to a port declared in the group's network block. If task.Resources.Ports cannot find the given label, the driver rejects the job because it has no host port to publish.","triggerScenarios":"StartTask -> createContainerConfig iterates driverConfig.Ports and task.Resources.Ports.Get(port) returns ok=false for a label not defined in any group network port stanza.","commonSituations":"Typos between the network port label and the driver's ports list; the port was declared with dynamic=true and its label mismatches; migrating jobs from the old port_map style without updating labels; forgetting the network block entirely.","solutions":["Ensure every label in the driver's ports list exists in the group's network block port stanza","Fix the label spelling so both sides match exactly","Declare the missing port in the group network block","For dynamic ports, verify the label is the one Nomad assigned, not the numeric value"],"exampleFix":"// before\ngroup \"app\" {\n  network { port \"http\" {} }\n  task \"web\" {\n    driver \"docker\" { ports = [\"http\", \"htpps\"] }\n  }\n}\n// after\ngroup \"app\" {\n  network { port \"http\" {} }\n  task \"web\" {\n    driver \"docker\" { ports = [\"http\"] }\n  }\n}","handlingStrategy":"validation","validationCode":"declared := map[string]bool{}\nfor _, p := range group.Network.Ports { declared[p.Label] = true }\nfor _, p := range cfg.Ports {\n  if !declared[p] {\n    return fmt.Errorf(\"port %q not declared in group network\", p)\n  }\n}","typeGuard":null,"tryCatchPattern":"err := client.StartTask(task); if err != nil && strings.Contains(err.Error(), \"not found, check network block\") { logMissingPortLabel(err) }","preventionTips":["Keep driver ports labels identical to network port labels","Declare every port in the group network block","Lint job specs for port label consistency"],"tags":["docker","nomad-driver","ports","network","config-validation"],"backgroundTag":"port-label-not-found","analyzedSha":"482b49bf1aec006f089bcfc7e632d8f6ac303e5e","analyzedAt":"2026-09-04T07:54:14.808Z","contentChangedAt":"2026-09-04T07:54:14.808Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}