nomad docker 镜像将从 Docker Hub 获取。但我想使用一些本地图像。我该如何使用主题。 (我不想使用私人仓库)
示例我想使用本地图像
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
}
}
}
}
错了!
我不确定这是否可以被视为答案或“黑客”。
但是,如果您希望 Nomad 使用节点上已存在的 docker 镜像,则该镜像不得标记为最新。
为了测试,我将图像标记为
IMAGE:local
。这样,Nomad 如果存在则使用它,如果不存在则从远程拉取它。
查看Nomad的源代码这里和这里,似乎不支持使用机器本地图像。这是有道理的,因为在具有多个节点的集群环境中,调度程序需要能够获取图像,无论作业分配到哪台机器。
(一种可能的解决方法是在 Nomad 集群中运行注册表服务,并使用对您来说最方便的存储后端)
Nomad 现在支持 tar docker 镜像。
这是一个例子
artifact {
source = "http://path.to/redis.tar"
}
config {
load = "redis.tar"
image = "redis"
}
但是,焦油大小可能太大而无法弹性传输和配置。
如果图片的标签是
:latest
,这是默认的,nomad会尝试拉取它。
本地图片使用不同的标签,例如
:local
,就可以了。
config {
image = "test:local"
}
虽然@Miao1007 s answer有效,但您需要注意一件事。看来您不能使用标签latest或完全省略标签(请参阅讨论here)。您需要使用一些版本号来标记您的 docker 版本,例如
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"
}