Starting with the default job file, I made some minor changes, an lo-behold it works! Changing the Consul key also successfully restarts the container.
My question is … “Why?”. Where in documentation does it say that this would work?
I have been searching a lot of the docs to find this specific mention as to why a template based environment variable can be referenced like this in the docker tag.
Hi @lgfa29 my question was only about the $DOCKER_TAG bit. (not that I am complaining, I am pleasantly happy)
i.e. As I hadn’t seen an actual example of this anywhere in docs, so I wasn’t sure it would have worked, that’s all.
I have already been using the other (Consul Template) functionalities for quite a few years now
The variable interpolation link mentions the ${attr......} variables, also the ${NOMAD_...} variables are sort of “known” to be visible in the “env”.
The fact that: “a variable fetched from Consul, then injected into the environment”, could be visible to the “pull” operation was not obvious to me when reading the template and the variable interpolation docs.
When this worked, I thought … “Has this always worked like this?!? I have doing this using a different method unnecessarily”
Oh, I am fully aware that you Nomad power user, and probably know more about it than me
I was just trying to set the context in case someone with less experience stumbled upon this post.
Ah got it. The NOMAD_* are special, in the sense that they can be interpolated in several other places, like, for example, check -> name. I think that’s why they are the only ones mentioned in the docs.
Other environment variables work in image because I think that string is passed directly to Docker and interpreted by the shell, so it’s more like a happy accident?
Hum…good question. Unfortunately I don’t think it’s possible, since the Nomad agent just passes the raw string to the Docker daemon.
I guess the Docker task driver could render the string before passing it along?
This would not update the cluster state though (i.e., changing the env var value would not cause the job to be updated, or the API won’t return the rendered values), but the task driver may be able to emit a better task event.
Could you open a feature request so we can track and discuss this better?
… but the more I think about this … there should be a separate feature request issue as well, which could show the image:tag for the Docker driver on the default task page of the GUI.