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 the task carries a DNS configuration, StartTask asks resolvconf.GenerateDNSMount to build a bind mount for /etc/resolv.conf in the task directory. Failure here (usually inability to write the generated resolv.conf under the task dir) prevents launch.

Source

Thrown at drivers/exec/driver.go:498

	}

	d.logger.Info("starting task", "driver_cfg", hclog.Fmt("%+v", driverConfig))
	handle = drivers.NewTaskHandle(taskHandleVersion)
	handle.Config = cfg

	pluginLogFile := filepath.Join(cfg.TaskDir().Dir, "executor.out")
	executorConfig := &executor.ExecutorConfig{
		LogFile:     pluginLogFile,
		LogLevel:    "debug",
		FSIsolation: true,
		Compute:     d.compute,
	}

	user := cfg.User
	if cfg.DNS != nil {
		dnsMount, err := resolvconf.GenerateDNSMount(cfg.TaskDir().Dir, cfg.DNS)
		if err != nil {
			return nil, nil, fmt.Errorf("failed to build mount for resolv.conf: %v", err)
		}
		cfg.Mounts = append(cfg.Mounts, dnsMount)
	}

	caps, err := capabilities.Calculate(
		capabilities.NomadDefaults(), d.config.AllowCaps, driverConfig.CapAdd, driverConfig.CapDrop,
	)
	if err != nil {
		return nil, nil, err
	}
	d.logger.Debug("task capabilities", "capabilities", caps)

	exec, pluginClient, err := executor.CreateExecutor(
		d.logger.With("task_name", handle.Config.Name, "alloc_id", handle.Config.AllocID),
		d.nomadConfig, executorConfig)
	if err != nil {
		return nil, nil, fmt.Errorf("failed to create executor: %v", err)
	}

View on GitHub (pinned to 482b49bf1a)

Solutions

  1. Check the task directory exists, is writable by the nomad user, and has free space (df).
  2. Fix permissions on the allocation/task dir (e.g., chown -R nomad:nomad).
  3. If custom DNS is unnecessary, remove the 'dns' block from the task to skip the mount.
  4. Check the wrapped error from GenerateDNSMount in client logs for the exact filesystem cause.

Example fix

// before (job)
resources { } 
task "app" { dns { servers = ["10.0.0.10"] } } // fails: task dir read-only
// after (on host)
sudo chown -R nomad:nomad /var/lib/nomad/client
# then resubmit the job unchanged
Defensive patterns

Strategy: validation

Validate before calling

// check task dir is writable before starting tasks with custom DNS
test := filepath.Join(taskDir, ".write-test")
if err := os.WriteFile(test, []byte("ok"), 0o644); err != nil {
    return fmt.Errorf("task dir not writable for resolv.conf: %w", err)
}
os.Remove(test)

Prevention

When it happens

Trigger: cfg.DNS is set and GenerateDNSMount fails writing the resolv.conf file into cfg.TaskDir().Dir, typically due to filesystem permissions, a read-only or full task dir, or path issues.

Common situations: Task directory permissions broken after restores; disk full on the client; chroot dir not writable by the nomad user; custom dns block in the job combined with restricted filesystems.

Related errors


AI-assisted analysis of hashicorp/nomad@482b49bf1a (2026-09-04). Data as JSON: /api/errors/090ba97c9036fa2f. Report an issue: GitHub.