{"record":{"id":"7173a336bed3759a","repo":"hashicorp/nomad","slug":"service-q-cannot-use-address-mode-driver-only","errorCode":null,"errorMessage":"service %q cannot use address_mode=\"driver\", only services defined in a \"task\" block can use this mode","messagePattern":"service %q cannot use address_mode=\"driver\", only services defined in a \"task\" block can use this mode","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"nomad/structs/structs.go","lineNumber":7539,"sourceCode":"\t\tid := unique{service.Name, \"group\", service.PortLabel}\n\t\tif !idSet.Insert(id) {\n\t\t\t// accumulate duplicates for a single error later on\n\t\t\tidDuplicateSet.Insert(id)\n\t\t}\n\n\t\t// Track that we have seen this service provider\n\t\tproviderSet.Insert(service.Provider)\n\n\t\tif err := service.Validate(); err != nil {\n\t\t\touter := fmt.Errorf(\"Service[%d] %s validation failed: %s\", i, service.Name, err)\n\t\t\tmErr.Errors = append(mErr.Errors, outer)\n\t\t\t// we break here to avoid the risk of crashing on null-pointer\n\t\t\t// access in a later step, accepting that we might miss out on\n\t\t\t// error messages to provide the user.\n\t\t\tcontinue\n\t\t}\n\t\tif service.AddressMode == AddressModeDriver {\n\t\t\tmErr.Errors = append(mErr.Errors, fmt.Errorf(\"service %q cannot use address_mode=\\\"driver\\\", only services defined in a \\\"task\\\" block can use this mode\", service.Name))\n\t\t}\n\n\t\tfor _, check := range service.Checks {\n\t\t\tif check.TaskName != \"\" {\n\t\t\t\tif check.AddressMode == AddressModeDriver {\n\t\t\t\t\tmErr.Errors = append(mErr.Errors, fmt.Errorf(\"Check %q invalid: cannot use address_mode=\\\"driver\\\", only checks defined in a \\\"task\\\" service block can use this mode\", service.Name))\n\t\t\t\t}\n\t\t\t\tif !taskSet.Contains(check.TaskName) {\n\t\t\t\t\tmErr.Errors = append(mErr.Errors,\n\t\t\t\t\t\tfmt.Errorf(\"Check %s invalid: refers to non-existent task %s\", check.Name, check.TaskName))\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\t// Produce an error of any services which are not unique enough in the group\n\t// i.e. have same <task, name, port>\n\tif idDuplicateSet.Size() > 0 {","sourceCodeStart":7521,"sourceCodeEnd":7557,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/nomad/structs/structs.go#L7521-L7557","documentation":"address_mode=\"driver\" (use the address/port reported by the task driver, e.g. Docker) is only valid for services defined inside a task block, because only task-level context has driver-provided addresses. A group-level service using this mode is rejected.","triggerScenarios":"A group-level services block sets address_mode = \"driver\"; validation appends this error for service.AddressMode == AddressModeDriver at group scope.","commonSituations":"Moving a service from a task to the group to share it, without switching address_mode from driver to host/auto; docs or examples written for task services applied at group level.","solutions":["Set address_mode = \"host\" (or \"auto\") on the group-level service.","Move the service into the task block if driver-reported addresses are required.","Use host_network/port labels that resolve at group level."],"exampleFix":"// before\ngroup \"g\" { service { name=\"s\" address_mode=\"driver\" } }\n// after\ngroup \"g\" { service { name=\"s\" address_mode=\"host\" port=\"http\" } }","handlingStrategy":"validation","validationCode":"if scope == \"group\" && svc.AddressMode == \"driver\" {\n  return fmt.Errorf(\"service %q: address_mode=driver not allowed at group level\", svc.Name)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use address_mode=host/auto in group services","Reserve driver mode for task-block services only","Document scope rules in internal job templates"],"tags":["nomad","service","address-mode","validation"],"backgroundTag":"invalid-address-mode","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"}