hashicorp/nomad · error

work_dir must be absolute but got relative path %q

Error message

work_dir must be absolute but got relative path %q

What it means

If the task sets work_dir, validate() requires it to be an absolute path (filepath.IsAbs). A relative work_dir would be ambiguous inside the chroot/isolated filesystem, so the task is rejected with this message.

Source

Thrown at drivers/exec/driver.go:244

	switch tc.ModeIPC {
	case "", executor.IsolationModePrivate, executor.IsolationModeHost:
	default:
		return fmt.Errorf("ipc_mode must be %q or %q, got %q", executor.IsolationModePrivate, executor.IsolationModeHost, tc.ModeIPC)
	}

	supported := capabilities.Supported()
	badAdds := supported.Difference(capabilities.New(tc.CapAdd))
	if !badAdds.Empty() {
		return fmt.Errorf("cap_add configured with capabilities not supported by system: %s", badAdds)
	}

	badDrops := supported.Difference(capabilities.New(tc.CapDrop))
	if !badDrops.Empty() {
		return fmt.Errorf("cap_drop configured with capabilities not supported by system: %s", badDrops)
	}

	if tc.WorkDir != "" && !filepath.IsAbs(tc.WorkDir) {
		return fmt.Errorf("work_dir must be absolute but got relative path %q", tc.WorkDir)
	}

	return nil
}

// TaskState is the state which is encoded in the handle returned in
// StartTask. This information is needed to rebuild the task state and handler
// during recovery.
type TaskState struct {
	ReattachConfig *pstructs.ReattachConfig
	TaskConfig     *drivers.TaskConfig
	Pid            int
	StartedAt      time.Time
}

type UserIDValidator interface {
	HasValidIDs(userName string) error
}

View on GitHub (pinned to 482b49bf1a)

Solutions

  1. Prefix work_dir with "/" to make it absolute (paths are interpreted within the task's chroot)
  2. Remove work_dir to use the default
  3. Fix templates that emit relative paths

Example fix

// before
config {
  work_dir = "opt/app"
}
// after
config {
  work_dir = "/opt/app"
}
Defensive patterns

Strategy: validation

Validate before calling

if tc.WorkDir != "" && !filepath.IsAbs(tc.WorkDir) {
  return fmt.Errorf("work_dir must be absolute: %q", tc.WorkDir)
}

Type guard

func isAbsWorkDir(p string) bool {
  return p == "" || filepath.IsAbs(p)
}

Try / catch

if err := task.Validate(); err != nil {
  if strings.Contains(err.Error(), "work_dir") {
    cfg.WorkDir = "/" + cfg.WorkDir
    err = task.Validate()
  }
  return err
}

Prevention

When it happens

Trigger: Task config work_dir = "app/bin" or similar relative path (any value that fails filepath.IsAbs while non-empty).

Common situations: Assuming work_dir is relative to the task dir like Docker WORKDIR conventions; porting configs where leading "/" was lost; templating errors producing relative paths.

Related errors


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