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
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
Cross-referencing https://github.com/hashicorp/nomad/issues/8919
Most helpful comment
โ๏ธ
Same - even after this thread and knowing what to look for I couldn't find this documented _anywhere_...
Using that in your template stanza causes
/alloc/app.confto 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