{"record":{"id":"04852edc3896b1bd","repo":"hashicorp/nomad","slug":"host-path-must-be-set-in-configuration-for-devices","errorCode":null,"errorMessage":"host path must be set in configuration for devices","messagePattern":"host path must be set in configuration for devices","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"drivers/docker/config.go","lineNumber":558,"sourceCode":"\tPassword   string `codec:\"password\"`\n\tServerAddr string `codec:\"server_address\"`\n}\n\ntype DockerDevice struct {\n\tHostPath          string `codec:\"host_path\"`\n\tContainerPath     string `codec:\"container_path\"`\n\tCgroupPermissions string `codec:\"cgroup_permissions\"`\n}\n\nfunc (d DockerDevice) toDockerDevice() (containerapi.DeviceMapping, error) {\n\tdd := containerapi.DeviceMapping{\n\t\tPathOnHost:        d.HostPath,\n\t\tPathInContainer:   d.ContainerPath,\n\t\tCgroupPermissions: d.CgroupPermissions,\n\t}\n\n\tif d.HostPath == \"\" {\n\t\treturn dd, fmt.Errorf(\"host path must be set in configuration for devices\")\n\t}\n\n\t// Docker's CLI defaults to HostPath in this case. See #16754\n\tif dd.PathInContainer == \"\" {\n\t\tdd.PathInContainer = d.HostPath\n\t}\n\n\tif dd.CgroupPermissions == \"\" {\n\t\tdd.CgroupPermissions = \"rwm\"\n\t}\n\n\tif !validateCgroupPermission(dd.CgroupPermissions) {\n\t\treturn dd, fmt.Errorf(\"invalid cgroup permission string: %q\", dd.CgroupPermissions)\n\t}\n\n\treturn dd, nil\n}\n","sourceCodeStart":540,"sourceCodeEnd":576,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/drivers/docker/config.go#L540-L576","documentation":"toDockerDevice validates the device stanza before converting it to Docker's device binding structure. A device configuration without HostPath is invalid because Docker needs a host-side path to mount into the container. Nomad returns this error immediately after building the partial DockerDevice, before any container creation.","triggerScenarios":"A task driver config device entry omits the host_path field (or it is an empty string) while toDockerDevice builds the docker.HostConfig device entry — e.g. `device { name = \"gpu\" }` with no host_path set in the Docker driver config.","commonSituations":"Typo in the config field name (e.g. path instead of host_path); HCL template rendering HostPath to an empty string; copying a config that relies on defaults that do not exist.","solutions":["Set host_path in the device stanza to an absolute host path (e.g. /dev/nvidia0)","Verify the rendered value is non-empty (check HCL/template interpolation)","If container_path is also omitted, note Nomad/Docker will default it to host_path — but host_path itself is always required","Validate the client config with `nomad agent -config ...` before deployment"],"exampleFix":"// before\ndevice {\n  name = \"gpu\"\n}\n// after\ndevice {\n  name            = \"gpu\"\n  host_path       = \"/dev/nvidia0\"\n  container_path  = \"/dev/nvidia0\"\n}","handlingStrategy":"validation","validationCode":"for _, d := range taskConfig.Devices {\n    if d.HostPath == \"\" {\n        return fmt.Errorf(\"device %q missing host_path\", d.Name)\n    }\n    if !filepath.IsAbs(d.HostPath) {\n        return fmt.Errorf(\"device host_path %q must be absolute\", d.HostPath)\n    }\n}","typeGuard":"func validDevice(d DeviceConfig) bool {\n    return d.HostPath != \"\" && filepath.IsAbs(d.HostPath)\n}","tryCatchPattern":"if err := agent.Start(); err != nil {\n    if strings.Contains(err.Error(), \"host path must be set\") {\n        // fix the device stanza host_path and reload the client\n    }\n}","preventionTips":["Always set host_path explicitly in every device stanza","Use absolute paths for host_path values","Validate HCL interpolation produces non-empty host_path values","Test client configs with `nomad agent -config` in CI before rollout"],"tags":["go","docker","nomad","config-validation","devices"],"backgroundTag":"missing-required-config-field","analyzedSha":"482b49bf1aec006f089bcfc7e632d8f6ac303e5e","analyzedAt":"2026-09-04T07:54:14.808Z","contentChangedAt":"2026-09-04T07:54:14.808Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}