{"record":{"id":"45065c4a571be243","repo":"hashicorp/nomad","slug":"failed-to-build-mount-for-resolv-conf-v","errorCode":null,"errorMessage":"failed to build mount for resolv.conf: %v","messagePattern":"failed to build mount for resolv\\.conf: (.+?)","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"drivers/docker/driver.go","lineNumber":1317,"sourceCode":"\t\t\thostConfig.Mounts = append(hostConfig.Mounts, mount.Mount{\n\t\t\t\tTarget:   etcHostMount.TaskPath,\n\t\t\t\tSource:   etcHostMount.HostPath,\n\t\t\t\tType:     \"bind\",\n\t\t\t\tReadOnly: etcHostMount.Readonly,\n\t\t\t\tBindOptions: &mount.BindOptions{\n\t\t\t\t\tPropagation: mount.Propagation(etcHostMount.PropagationMode),\n\t\t\t\t},\n\t\t\t})\n\t\t}\n\t}\n\n\t// Setup DNS\n\t// If task DNS options are configured Nomad will manage the resolv.conf file\n\t// Docker driver dns options are not compatible with task dns options\n\tif task.DNS != nil {\n\t\tdnsMount, err := resolvconf.GenerateDNSMount(task.TaskDir().Dir, task.DNS)\n\t\tif err != nil {\n\t\t\treturn c, fmt.Errorf(\"failed to build mount for resolv.conf: %v\", err)\n\t\t}\n\t\thostConfig.Mounts = append(hostConfig.Mounts, mount.Mount{\n\t\t\tTarget:   dnsMount.TaskPath,\n\t\t\tSource:   dnsMount.HostPath,\n\t\t\tType:     \"bind\",\n\t\t\tReadOnly: dnsMount.Readonly,\n\t\t\tBindOptions: &mount.BindOptions{\n\t\t\t\tPropagation: mount.Propagation(dnsMount.PropagationMode),\n\t\t\t},\n\t\t})\n\t} else {\n\t\tif len(driverConfig.DNSSearchDomains) > 0 {\n\t\t\thostConfig.DNSSearch = driverConfig.DNSSearchDomains\n\t\t}\n\t\tif len(driverConfig.DNSOptions) > 0 {\n\t\t\thostConfig.DNSOptions = driverConfig.DNSOptions\n\t\t}\n\t\t// set DNS servers","sourceCodeStart":1299,"sourceCodeEnd":1335,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/drivers/docker/driver.go#L1299-L1335","documentation":"When a task block defines a dns block, Nomad generates a resolv.conf bind mount via resolvconf.GenerateDNSMount instead of passing Docker dns options. If the generator fails (invalid DNS configuration or filesystem problems in the task dir), the error is wrapped with this message and container creation stops.","triggerScenarios":"StartTask -> createContainerConfig with task.DNS != nil where GenerateDNSMount(task.TaskDir().Dir, task.DNS) errors, typically from malformed DNS config (empty servers, bad option format) or inability to prepare the file in the task dir.","commonSituations":"dns blocks with servers/searches/options entries containing invalid characters; read-only or full task directories; upgrades where stale alloc state blocks writing resolv.conf.","solutions":["Fix the task's dns block: supply valid servers/searches/options values","Check the task directory is writable and has free space","Read the wrapped %v inner error to pinpoint the exact DNS field or file failure","Remove the dns block to fall back to Docker's default DNS handling"],"exampleFix":"// before\ntask \"web\" {\n  driver = \"docker\"\n  dns {\n    servers = [\"\"]\n  }\n}\n// after\ntask \"web\" {\n  driver = \"docker\"\n  dns {\n    servers = [\"1.1.1.1\", \"8.8.8.8\"]\n  }\n}","handlingStrategy":"validation","validationCode":"for _, s := range task.DNS.Servers {\n  if net.ParseIP(s) == nil && s != \"\" {\n    return fmt.Errorf(\"invalid dns server: %q\", s)\n  }\n}","typeGuard":null,"tryCatchPattern":"err := client.StartTask(task); if err != nil && strings.Contains(err.Error(), \"failed to build mount for resolv.conf\") { logRootCause(err); fixDNSBlock() }","preventionTips":["Only use valid IPs in dns.servers","Keep the task dir writable with free space","Remove empty strings from dns fields"],"tags":["docker","nomad-driver","dns","resolv-conf","mount"],"backgroundTag":"mount-generation-failed","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"}