Update docker tag of existing job (task)

For a specific (job, group, task), what would be the easiest way to update the docker image tag of an existing (job, group, task). HTTP API, any existing cmdline tool, anything else?

Scenario: I have a batch (periodic) job already submitted and I want to update the docker image that it uses.

I was wondering if there is a simpler alternative to "downloading the job JSON and resubmitting it with changed parameters)

I want to do this via automation, hence the question. Normally I would edit the jobfile and resubmit manually.

Job descriptions in HCL support variables, so you can do something like:

variable "image_tag" {
  type        = string
  description = "Docker image tag to deploy."
  default     = "latest"

job "myjob" {
  // …
  group "mygroup" {
    task "mytask" {
      driver = "docker"

      config {
        image = "my_image:${var.image_tag}"
        // … 

and run

nomad job run -var "image_tag=1.2.3" myjob.hcl

This can run in an automated fashion as well. Using variables, the job description is always up to date and you don’t have a difference on what version is applied on your cluster and what version is stored in the job file.


Thanks for this, the above would perfectly work, but …

we have a slightly additional problem, our Nomad jobs are Terraformed, and the way the file structure is, it is applicable to multiple jobs using the same image.

So, ideally I want to do the following:

  • update the “docker tag” in sources somehow.
  • run an api and also update the running job.

I want to avoid doing the following:

  • update the docker tag in the repo somewhere.
  • run the “terraform apply” command.

Now that I have typed this … I can think of some optimizations of our current jobs:

  • either separate jobs based on namespace so I can handle bunch of jobs separately.
  • in addition to namespaces, prefix the jobs to be able to ensure that I update only certain jobs.

Updating image tags is perfectly fine in nomad with using consul keys.

You can define the environment var IMAGE_TAG in an environment template(env=true) and use that variable within the image param of the docker driver config.

thanks, I think after I posted this question, I figured out the “env variable from Consul” method here:


1 Like