hashicorp/nomad · error
path was not relative to the mount task path
Error message
path was not relative to the mount task path
What it means
getPathInMount resolves a binary located under a mount by relating the bin path to the mount's task-side path. If filepath.Rel(mountTaskPath, bin) fails or is empty, the bin was not under the mount's task path and this error is thrown.
Source
Thrown at drivers/shared/executor/executor_linux_cgo.go:1077
// Turn relative-to-taskdir path into re-rooted absolute path to avoid
// libcontainer trying to resolve the binary using $PATH.
// Do *not* use filepath.Join as it will translate ".."s returned by
// filepath.Rel. Prepending "/" will cause the path to be rooted in the
// chroot which is the desired behavior.
return filepath.Clean("/" + rel), hostPath, nil
}
// getPathInMount for the binary in the mount's host path, constructing the path
// considering that the bin path is rooted in the mount's task path and not its
// host path. It returns the absolute path rooted inside the container and the
// absolute path on the host.
func getPathInMount(mountHostPath, mountTaskPath, bin string) (string, string, error) {
// Find the path relative to the mount point in the task so that we can
// trim off any shared prefix when we search on the host path
mountRel, err := filepath.Rel(mountTaskPath, bin)
if mountRel == "" || err != nil {
return "", "", fmt.Errorf("path was not relative to the mount task path")
}
hostPath := filepath.Join(mountHostPath, mountRel)
err = filepathIsRegular(hostPath)
if err != nil {
return "", "", err
}
// Turn relative-to-taskdir path into re-rooted absolute path to avoid
// libcontainer trying to resolve the binary using $PATH.
// Do *not* use filepath.Join as it will translate ".."s returned by
// filepath.Rel. Prepending "/" will cause the path to be rooted in the
// chroot which is the desired behavior.
return filepath.Clean("/" + bin), hostPath, nil
}
// filepathIsRegular verifies that a filepath is a regular file (i.e. not aView on GitHub (pinned to 482b49bf1a)
Solutions
- Ensure the command binary resides under the declared mount's task path
- Fix the mount definitions (task path vs host path) in the job/driver config
- Verify paths are clean/absolute and consistently formatted
- Check host volume/CSI mount options so the mount actually contains the binary
Example fix
// before
command = "/opt/bin/app" # not under mounted local/
mounts = [{ task_path = "local", host_path = "/srv/share" }]
// after
command = "local/app" # or place binary inside the mount Defensive patterns
Strategy: validation
Validate before calling
if !strings.HasPrefix(bin, mount.TaskPath) {
return fmt.Errorf("bin %q not under mount task path %q", bin, mount.TaskPath)
} Try / catch
if err != nil && strings.Contains(err.Error(), "not relative to the mount task path") {
// bin lives outside this mount; adjust mounts or command path
return fmt.Errorf("mount/command mismatch: %w", err)
} Prevention
- Place the command binary inside a declared mount's task path
- Keep mount task_path and host_path definitions consistent
- Clean and absolutize both paths before comparison
When it happens
Trigger: lookupTaskBin iterates task mounts; for each mount whose task path should prefix the bin, if bin is not beneath mountTaskPath (or paths are inconsistent), this error is returned for that mount.
Common situations: Binary lives outside the mount being searched; mount task path configured differently between host and task views (custom CSI/host volume mounts); typo'd mount definitions in the driver config; path casing/trailing-slash inconsistencies.
Related errors
- failed to determine relative path base=%q target=%q: %v
- ErrCgroupMustBeSet
- user name must contain domain
- failed to resolve alloc directory: %w
- failed to resolve requested path: %w
AI-assisted analysis of hashicorp/nomad@482b49bf1a (2026-09-04).
Data as JSON: /api/errors/06871247baca75d8.
Report an issue: GitHub.