hashicorp/nomad · error
failed to build mount for resolv.conf: %v
Error message
failed to build mount for resolv.conf: %v
What it means
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.
Source
Thrown at drivers/docker/driver.go:1317
hostConfig.Mounts = append(hostConfig.Mounts, mount.Mount{
Target: etcHostMount.TaskPath,
Source: etcHostMount.HostPath,
Type: "bind",
ReadOnly: etcHostMount.Readonly,
BindOptions: &mount.BindOptions{
Propagation: mount.Propagation(etcHostMount.PropagationMode),
},
})
}
}
// Setup DNS
// If task DNS options are configured Nomad will manage the resolv.conf file
// Docker driver dns options are not compatible with task dns options
if task.DNS != nil {
dnsMount, err := resolvconf.GenerateDNSMount(task.TaskDir().Dir, task.DNS)
if err != nil {
return c, fmt.Errorf("failed to build mount for resolv.conf: %v", err)
}
hostConfig.Mounts = append(hostConfig.Mounts, mount.Mount{
Target: dnsMount.TaskPath,
Source: dnsMount.HostPath,
Type: "bind",
ReadOnly: dnsMount.Readonly,
BindOptions: &mount.BindOptions{
Propagation: mount.Propagation(dnsMount.PropagationMode),
},
})
} else {
if len(driverConfig.DNSSearchDomains) > 0 {
hostConfig.DNSSearch = driverConfig.DNSSearchDomains
}
if len(driverConfig.DNSOptions) > 0 {
hostConfig.DNSOptions = driverConfig.DNSOptions
}
// set DNS serversView on GitHub (pinned to 482b49bf1a)
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
Example fix
// before
task "web" {
driver = "docker"
dns {
servers = [""]
}
}
// after
task "web" {
driver = "docker"
dns {
servers = ["1.1.1.1", "8.8.8.8"]
}
} Defensive patterns
Strategy: validation
Validate before calling
for _, s := range task.DNS.Servers {
if net.ParseIP(s) == nil && s != "" {
return fmt.Errorf("invalid dns server: %q", s)
}
} Try / catch
err := client.StartTask(task); if err != nil && strings.Contains(err.Error(), "failed to build mount for resolv.conf") { logRootCause(err); fixDNSBlock() } Prevention
- Only use valid IPs in dns.servers
- Keep the task dir writable with free space
- Remove empty strings from dns fields
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- failed to build mount for /etc/hosts: %v
- invalid source, must be "" for tmpfs
- invalid mount type, must be "bind", "volume", "tmpfs": %q
- failed to reattach to docker logger process: %v
- failed to launch docker logger plugin: %v
AI-assisted analysis of hashicorp/nomad@482b49bf1a (2026-09-04).
Data as JSON: /api/errors/45065c4a571be243.
Report an issue: GitHub.