Nomad: Bad UX when rendering template to shared alloc directory with Docker driver

Created on 2 Aug 2017  ยท  6Comments  ยท  Source: hashicorp/nomad

Based on conversation on gitter.

Relevant parts of my job file:

job "sf-demo" {
  group "frontend" {
    task "web" {
      template {
        destination = "${NOMAD_ALLOC_DIR}/conf.d/db.php"
        change_mode = "noop"
        data = "some stuff"
      }
    } #task web

    task "redis" {
       ...
    }
  }
}

The directory tree looks like:

โ”œโ”€โ”€ alloc
โ”‚ย ย  โ”œโ”€โ”€ data
โ”‚ย ย  โ”œโ”€โ”€ logs
โ”‚ย ย  โ”‚ย ย  โ”œโ”€โ”€ redis.stderr.0
โ”‚ย ย  โ”‚ย ย  โ””โ”€โ”€ redis.stdout.0
โ”‚ย ย  โ””โ”€โ”€ tmp
โ”œโ”€โ”€ redis
โ”‚ย ย  โ”œโ”€โ”€ executor.out
โ”‚ย ย  โ”œโ”€โ”€ local
โ”‚ย ย  โ”œโ”€โ”€ secrets
โ”‚ย ย  โ””โ”€โ”€ tmp
โ””โ”€โ”€ web
    โ”œโ”€โ”€ alloc
    โ”‚ย ย  โ””โ”€โ”€ conf.d
    โ”‚ย ย      โ””โ”€โ”€ db.php
    โ”œโ”€โ”€ local
    โ”œโ”€โ”€ secrets
    โ””โ”€โ”€ tmp

Nomad version 0.6.0

stagneeds-discussion themcleanup themdocs themtemplate typenhancement

Most helpful comment

โ˜๏ธ

Same - even after this thread and knowing what to look for I couldn't find this documented _anywhere_...

        destination = "../alloc/app.conf"

Using that in your template stanza causes /alloc/app.conf to exist inside the Docker container for all tasks within a group. This isn't really very intuitive and given that Nomad (mostly) isolates the host filesystem with Docker, I didn't even consider trying ../ because I assumed it'd be rejected on eval.

Voting to get this fixed to be consisted with the other task drivers or at least documented under the Docker driver

All 6 comments

Hey,

When rendering the template to the shared allocation directory with the docker driver, you need to change the path to be ../alloc/<path you want>. This unfortunately has to do with the fact that the environment variable is set to the path that exists in the container but the rendering is happening rooted at the task directory. This is causing the allocation to be rendered to an alloc directory under the web task instead of the shared alloc directory.

Huge +1 here. It's really annoying that NOMAD_ALLOC_DIR is /alloc, but the _actual_ location is/${NOMAD_TASK_NAME}/${NOMAD_ALLOC_DIR}, and that there's no env var for the root /alloc.

Hey @dadgar , is this behaviour documented somewhere?

I faced this same issue now. I already use the shared allocation dir to have a filebeat sidecar to various other tasks but when I tried to share an artifact among tasks (one being exec and the other one being docker) the job failed hard because the service could not start for not being able to find the files.

โ˜๏ธ

Same - even after this thread and knowing what to look for I couldn't find this documented _anywhere_...

        destination = "../alloc/app.conf"

Using that in your template stanza causes /alloc/app.conf to exist inside the Docker container for all tasks within a group. This isn't really very intuitive and given that Nomad (mostly) isolates the host filesystem with Docker, I didn't even consider trying ../ because I assumed it'd be rejected on eval.

Voting to get this fixed to be consisted with the other task drivers or at least documented under the Docker driver

Was this page helpful?
0 / 5 - 0 ratings