How can I make a nomad job use a local docker image?
Asked Answered
A

6

10

nomad docker image will be fetched from Docker Hub. But I have want use some local images. How can I use theme. (I dont want to use private repo)

Example I want to use local image test


> docker images
REPOSITORY                         TAG                 IMAGE ID            CREATED             SIZE
test                        latest              da795ca8a32f        36 minutes ago      567MB
job "test" {
  datacenters = ["dc1"]

  group "example" {
    task "test" {
      driver = "docker"

      config {
        image = "test"
      }

      resources {
        cpu = 500
        memory = 256 
      }
    }
  }
}

It's wrong !

Adolescence answered 28/5, 2019 at 12:43 Comment(0)
M
3

Looking at Nomad's source code here and here, it seems that using machine local images is not supported. That would make sense, as in a cluster environment with several nodes, the scheduler needs to be able to get the image irrespective of which machine the job is allocated to.

(One possible workaround would be to run a registry service within the Nomad cluster, and use whichever storage backend is most convenient for you)

Modestamodeste answered 28/5, 2019 at 14:14 Comment(0)
B
7

I'm not sure if this can be treated as an answer or a "hack".

But if you want Nomad to use docker image that is already present on a node the image MUST NOT be tagged latest.

For testing I tag my images as IMAGE:local. This way Nomad uses it if present, pulls it from remote if not.

Bash answered 31/12, 2020 at 10:7 Comment(2)
Note that, by default, Nomad will delete this image after use and you'll have to rebuild it nomadproject.io/docs/drivers/docker#gcNyssa
@Nyssa Did not happen to me yet. config.gc.image=falseBash
M
3

Looking at Nomad's source code here and here, it seems that using machine local images is not supported. That would make sense, as in a cluster environment with several nodes, the scheduler needs to be able to get the image irrespective of which machine the job is allocated to.

(One possible workaround would be to run a registry service within the Nomad cluster, and use whichever storage backend is most convenient for you)

Modestamodeste answered 28/5, 2019 at 14:14 Comment(0)
D
3

Nomad now supports tar docker images.

here is an example

artifact {
  source = "http://path.to/redis.tar"
}
config {
  load = "redis.tar"
  image = "redis"
}

However, the tar size may be too large to be resiliently transport and provisioned.

Daglock answered 8/11, 2019 at 17:34 Comment(0)
S
2

If the tag of the image is :latest, which is the default, nomad will try to pull it.

Use a different tag for local images, for example :local, and it will be fine.

  config {
    image = "test:local"
  }
Sold answered 8/5, 2023 at 5:49 Comment(1)
This should be the accepted answer.Dayfly
K
0

While @Miao1007 s answer works, you need to be aware of one thing. It seems that you you cannot use the tag latest or omit the tag altogether ( see the discussion here). You need to tag your docker build with some version number like

sudo docker build --tag dokr:1.0.0 .
sudo docker save dokr:1.0.0 > dokr-1.0.0.tar

then use the following in the job file
artifact {
    source = "http://localhost:8000/dokr-1.0.0.tar"
}
config {
    load = "go-docker-dokr-1.0.0.tar"
    image = "go-docker-dokr:1.0.0"
}
Korenblat answered 9/2, 2022 at 16:1 Comment(0)
C
0

Starting from version 0.9.0, Nomad checking whether the image has already been loaded.

  • Source code

  • Contributor comment

     // We're going to check whether the image is already downloaded. If the tag
     // is "latest", or ForcePull is set, we have to check for a new version every time so we don't
     // bother to check and cache the id here. We'll download first, then cache.
    
Canst answered 31/1, 2023 at 5:40 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.