hashicorp/nomad · error

work_dir must be an absolute path: %s

Error message

work_dir must be an absolute path: %s

What it means

This error is thrown by the Nomad Java driver's validate() when the work_dir config field is set to a relative path. The working directory for the Java task must be an absolute path (checked with filepath.IsAbs), because the executor needs an unambiguous filesystem location independent of where the executor process starts. Empty work_dir is allowed (the task's default directory is used).

Source

Thrown at drivers/java/driver.go:223

	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 an absolute path: %s", tc.WorkDir)
	}
	return nil
}

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

// Driver is a driver for running images via Java
type Driver struct {
	// eventer is used to handle multiplexing of TaskEvents calls such that an
	// event can be broadcast to all callers

View on GitHub (pinned to 482b49bf1a)

Solutions

  1. Prefix the path with '/' to make it absolute, e.g. /opt/app/work
  2. Use the task's directory (NomadEnvTaskDir/alloc dir) instead of leaving a relative work_dir
  3. Remove work_dir entirely if the default task directory is acceptable
  4. Fix empty template variables that were supposed to supply the absolute prefix

Example fix

// before
-work_dir = "app/workdir"
// after
-work_dir = "/opt/app/workdir"
Defensive patterns

Strategy: validation

Validate before calling

func checkWorkDir(wd string) error {
    if wd != "" && !filepath.IsAbs(wd) {
        return fmt.Errorf("work_dir must be an absolute path: %s", wd)
    }
    return nil
}

Prevention

When it happens

Trigger: Setting work_dir = "app/work" or "./bin" (no leading slash) in a Java task's driver config, then starting the task.

Common situations: Configs copied from Windows/Unix or written assuming a default base directory; templated configs where a path prefix variable is empty; users confusing work_dir with the task directory which is relative.

Related errors


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