8

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 !

zhangslob
  • 189
  • 1
  • 2
  • 8

6 Answers6

6

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.

titus
  • 377
  • 4
  • 16
  • Note that, by default, Nomad will delete this image after use and you'll have to rebuild it https://www.nomadproject.io/docs/drivers/docker#gc – Andrew Jun 27 '22 at 17:31
  • @Andrew Did not happen to me yet. config.gc.image=false – titus Jun 28 '22 at 18:38
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)

JamesJJ
  • 874
  • 8
  • 11
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.

Miao1007
  • 944
  • 6
  • 22
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"
}
S Ghosh
  • 376
  • 4
  • 5
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.
    
qreodium
  • 33
  • 6
0

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"
  }
KamilCuk
  • 120,984
  • 8
  • 59
  • 111