zhangslob
zhangslob

Reputation: 329

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

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 !

Upvotes: 11

Views: 5878

Answers (6)

KamilCuk
KamilCuk

Reputation: 141698

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"
  }

Upvotes: 3

qreodium
qreodium

Reputation: 63

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.
    

Upvotes: 0

S Ghosh
S Ghosh

Reputation: 464

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"
}

Upvotes: 0

titus
titus

Reputation: 426

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.

Upvotes: 7

Miao1007
Miao1007

Reputation: 974

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.

Upvotes: 4

JamesJJ
JamesJJ

Reputation: 954

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)

Upvotes: 4

Related Questions