Closed tgross closed 4 years ago
Oh, and for completeness, nomad alloc fs
sees the allocation's directory on the host (which isn't the same as NOMAD_ALLOC_DIR
), and can see our "hidden" file as a result, but the task can't do anything with it!
$ nomad alloc fs a2c
Mode Size Modified Time Name
drwxrwxrwx 4.0 KiB 2020-09-17T19:12:32Z alloc/
drwxrwxrwx 4.0 KiB 2020-09-17T19:12:29Z dockertask/
drwxrwxrwx 4.0 KiB 2020-09-17T19:12:32Z exectask/
drwxrwxrwx 4.0 KiB 2020-09-17T19:12:32Z rawexectask/
$ nomad alloc fs a2c dockertask
Mode Size Modified Time Name
drwxrwxrwx 4.0 KiB 2020-09-17T19:12:31Z local/
drwxrwxrwx 60 B 2020-09-17T19:12:29Z secrets/
dtrwxrwxrwx 4.0 KiB 2020-09-17T19:12:29Z tmp/
-rw-r--r-- 27 B 2020-09-17T19:12:29Z weird-dockertask-was-here
This also has some interesting impact with templates and absolute directories, such as https://github.com/hashicorp/nomad/issues/8962
Cross-referencing https://github.com/hashicorp/nomad/issues/2948
Working up a PR for this.
I'm going to lock this issue because it has been closed for 120 days ⏳. This helps our maintainers find and focus on the active issues. If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.
The task directories documentation contains the following text:
Meanwhile, the
template
documentation includes this bit:The
NOMAD_TASK_DIR
is thelocal/
directory provided to each task, whereas the "task directory" is the directory that Nomad uses to set up the task, and may not be the actual filesystem of the task, depending on the driver. This turns out to be quite different betweenraw_exec
/exec
anddocker
tasks.There's nothing we're doing wrong here per se, but the behavior could be better described, particularly around the use of templates where it's possible to write a template that can't be seen from inside a Docker container. This issue is to anchor a discussion about how we want to document this better.
The following jobspec illustrates some of the interesting behavioral differences:
If we look at the logs for the three tasks, we see that the
raw_exec
andexec
jobs have their script file at/script.sh
, whereas the Docker task has its at/local/script.sh
. We had to do this because the "relative" path of./script.sh
is not available inside the Docker container. First, the logs:nomad alloc logs dockertask
``` $ nomad alloc logs a2c dockertask --- environment ---------------------------- NOMAD_ALLOC_DIR: /alloc NOMAD_TASK_DIR: /local --- root dir ---------------------------- alloc bin dev etc home local proc root secrets sys tmp usr var --- alloc dir ---------------------------- /alloc /alloc/container /alloc/container/871cc932_8058_22a4_f90c_a238fec755bc /alloc/container/871cc932_8058_22a4_f90c_a238fec755bc/state.json /alloc/container/fd83a19b_7dfb_f90e_361c_1fa06e7b7c8a /alloc/container/fd83a19b_7dfb_f90e_361c_1fa06e7b7c8a/state.json /alloc/data /alloc/logs /alloc/logs/.rawexectask.stdout.fifo /alloc/logs/exectask.stdout.0 /alloc/logs/exectask.stderr.0 /alloc/logs/dockertask.stdout.0 /alloc/logs/rawexectask.stdout.0 /alloc/logs/.exectask.stdout.fifo /alloc/logs/rawexectask.stderr.0 /alloc/logs/.dockertask.stderr.fifo /alloc/logs/.rawexectask.stderr.fifo /alloc/logs/.exectask.stderr.fifo /alloc/logs/.dockertask.stdout.fifo /alloc/logs/dockertask.stderr.0 /alloc/tmp --- task dir ---------------------------- /local /local/script.sh /local/dockertask-was-here ```nomad alloc logs exectask
``` $ nomad alloc logs a2c exectask --- environment ---------------------------- NOMAD_ALLOC_DIR: /alloc NOMAD_TASK_DIR: /local --- root dir ---------------------------- alloc bin dev etc executor.out lib lib32 lib64 local proc run sbin script.sh secrets sys tmp usr --- alloc dir ---------------------------- /alloc /alloc/container /alloc/data /alloc/logs /alloc/logs/.rawexectask.stdout.fifo /alloc/logs/exectask.stdout.0 /alloc/logs/exectask.stderr.0 /alloc/logs/dockertask.stdout.0 /alloc/logs/rawexectask.stdout.0 /alloc/logs/.exectask.stdout.fifo /alloc/logs/rawexectask.stderr.0 /alloc/logs/.dockertask.stderr.fifo /alloc/logs/.rawexectask.stderr.fifo /alloc/logs/.exectask.stderr.fifo /alloc/logs/.dockertask.stdout.fifo /alloc/logs/dockertask.stderr.0 /alloc/tmp --- task dir ---------------------------- /local /local/exectask-was-here ```nomad alloc logs exectask
``` $ nomad alloc logs a2c rawexectask --- environment ---------------------------- NOMAD_ALLOC_DIR: /alloc NOMAD_TASK_DIR: /local --- root dir ---------------------------- alloc bin dev etc executor.out lib lib32 lib64 local proc run sbin script.sh secrets sys tmp usr --- alloc dir ---------------------------- /alloc /alloc/container /alloc/data /alloc/logs /alloc/logs/.rawexectask.stdout.fifo /alloc/logs/exectask.stdout.0 /alloc/logs/exectask.stderr.0 /alloc/logs/dockertask.stdout.0 /alloc/logs/rawexectask.stdout.0 /alloc/logs/.exectask.stdout.fifo /alloc/logs/rawexectask.stderr.0 /alloc/logs/.dockertask.stderr.fifo /alloc/logs/.rawexectask.stderr.fifo /alloc/logs/.exectask.stderr.fifo /alloc/logs/.dockertask.stdout.fifo /alloc/logs/dockertask.stderr.0 /alloc/tmp --- task dir ---------------------------- /local /local/rawexectask-was-here ```If we then go into the Nomad datadir for the allocation, we see the following:
The
rawexectask
directory is the working directory of ourraw_exec
task, full of hardlinks back to the host:The
exectask
directory is the working directory of ourexec
task, full of bind-mounts from the host:But the
dockertask
directory is the working directory of the task, but includes only the bind-mounts that we add for/alloc
,/local
, and/secrets
. The rest of the overlay filesystem unpacked by the Docker driver is elsewhere. So we can see theweird-dockertask-was-here
in the allocation's "task directory" on the host, but not inside the running container.The Nomad-defined mounts for the container:
cc @angrycub @notnoop