{{tag>nomad hashicorp volumes}} ====== Nomad volumes ====== ===== Static volume ===== Define these on the client node. # cat /etc/nomad/nomad.hcl data_dir = "/var/lib/nomad" bind_addr = "192.168.56.109" client { enabled = true servers = ["192.168.56.105", "192.168.56.106", "192.168.56.107"] host_volume "my-data-volume" { path = "/opt/hashicorp" read_only = false } } Restart nomad and use it in a job: job "write‑file" { # Run the job once (no periodic scheduling) type = "batch" # Optional: limit the job to a single allocation datacenters = ["dc1"] group "writer" { count = 1 task "create-file" { driver = "docker" config { # Small Alpine image with /bin/sh image = "alpine:latest" # The command that creates the file command = "/bin/sh" args = ["-c", "echo 'Hello from Nomad!' > /custom/output.txt"] } # Mount a writable volume so the file persists after the container stops resources { cpu = 100 # MHz memory = 64 # MB } # Define a host‑side volume (optional – if you want the file on the host) volume_mount { volume = "example1" destination = "/custom" read_only = false } } # Optional: define a named volume that maps to a host directory volume "example1" { type = "host" source = "my-data-volume" } } } You will find the output at ''/opt/hashicorp/output.txt'' on a client node where this volume is defined. ===== Dynamic volumes ===== These can be created on any client and if constraints are not specified nomad will iterate over the available clients and [[https://developer.hashicorp.com/nomad/docs/other-specifications/volume/host#volume-placement|choose one to create]] it on. # cat dyn-vol.hcl name = "example" type = "host" plugin_id = "mkdir" capability { access_mode = "single-node-single-writer" attachment_mode = "file-system" } Create the volume # nomad volume create dyn-vol.hcl ==> Created host volume example with ID ad332141-073f-cc90-8c39-a0bb470a4970 ✓ Host volume "ad332141" ready 2025-11-06T10:26:15Z ID = ad332141-073f-cc90-8c39-a0bb470a4970 Name = example Namespace = default Plugin ID = mkdir Node ID = 28105807-febd-505a-d0bb-006443663051 Node Pool = default Capacity = 0 B State = ready Host Path = /var/lib/nomad/host_volumes/ad332141-073f-cc90-8c39-a0bb470a4970 # nomad volume status Dynamic Host Volumes ID Name Namespace Plugin ID Node ID Node Pool State ad332141 example default mkdir 28105807 default ready This will create it somewhere at ''/var/lib/nomad/host_volumes/ad332141-073f-cc90-8c39-a0bb470a4970/'', the UUID will be different. Use it in job job "write‑file" { # Run the job once (no periodic scheduling) type = "batch" # Optional: limit the job to a single allocation datacenters = ["dc1"] group "writer" { count = 1 task "create-file" { driver = "docker" config { # Small Alpine image with /bin/sh image = "alpine:latest" # The command that creates the file command = "/bin/sh" args = ["-c", "echo 'Hello from Nomad!' > /custom/output.txt"] } # Mount a writable volume so the file persists after the container stops resources { cpu = 100 # MHz memory = 64 # MB } # Define a host‑side volume (optional – if you want the file on the host) # Uncomment the block below and adjust the path as needed. volume_mount { volume = "example1" destination = "/custom" read_only = false } } # Optional: define a named volume that maps to a host directory volume "example1" { type = "host" source = "example" access_mode = "single-node-single-writer" attachment_mode = "file-system" } } } ====== Tested on ====== * nomad 1.10.5 * AlmaLinux release 9.6 (Sage Margay) ====== See also ====== ====== References ====== * https://blog.bitexpert.de/blog/nomad_dynamic_host_volumes * https://developer.hashicorp.com/nomad/docs/other-specifications/volume/host#nomad-dynamic-host-volume-specification