2

I'm new to nomad and I try to move from docker-compose files in which I'm used to mount folders to a relative location of the docker-compose.yml file.

I've trouble understanding how I can reproduce this behavior using nomad.

If I were to do it manually I would do something using the $PWD env var: docker run --rm -it -v $PWD/packs/hello_pack:/app node bash

Unfortunately I can't find any example of a bind mount a relative folder with nomad.

I tried without any luck

  task "server" {
      driver = "docker"

      config {
        image= "node:lts-buster-slim"

        mount {
          type = "bind"
          target = "/app"
          source = "./"
        }

        …

      }
   }

I think this is a convenient feature to have during development phase.

Is there a way to mount a folder relative to the current directory (or something similar)?

nlko
  • 151
  • 1
  • 6

2 Answers2

0

I think this should do: https://www.nomadproject.io/docs/drivers/docker#volumes

config {
  volumes = [
    # Use absolute paths to mount arbitrary paths on the host
    "/path/on/host:/path/in/container",

    # Use relative paths to rebind paths already in the allocation dir
    "relative/to/task:/also/in/container"
  ]
}
Stas
  • 1,707
  • 15
  • 25
  • Thanks for helping but this is only valid for relative folders within the allocation dir while I'm trying to mount a relative path from the host. – nlko Feb 23 '22 at 20:03
0

You can use abspath(".") hcl2 function to get current working directory.

locals {
   pwd = "${abspath(".")}"
}

...
   source = "${locals.pwd}"

Note that this is working directory when executing nomad, not the directory that contains job file. I have found no way of getting the directory of currently processed nomad job file inside hcl2.

https://developer.hashicorp.com/nomad/docs/job-specification/hcl2/locals https://developer.hashicorp.com/nomad/docs/job-specification/hcl2/functions/file/abspath

If I were to do it manually I would do something using the $PWD env var: docker run --rm -it -v $PWD/packs/hello_pack:/app node bash

You can also pass arguments to nomad job. https://developer.hashicorp.com/nomad/docs/job-specification/hcl2/variables

KamilCuk
  • 120,984
  • 8
  • 59
  • 111