Docker Swarm部署本地Dockerfile

时间:2018-03-19 05:03:24

标签: docker docker-compose dockerfile docker-swarm

我正在尝试在本地计算机上的swarm中部署一堆服务以进行测试,并且我想在每次运行或从管理器节点部署堆栈时构建docker镜像。

我想要实现的目标是否可能......

3 个答案:

答案 0 :(得分:1)

在Docker Swarm上,您无法构建Docker Compose文件中指定的图像:

  

注意:使用(版本3)Compose文件在群集模式下部署堆栈时,将忽略此选项。 docker stack命令仅接受预先构建的图像。 - from docker docs

您需要使用docker build创建图像(位于Dockerfile所在的文件夹中):

docker build -t imagename --no-cache .

在此命令之后,图像(名为imagename)现在可在本地注册表中使用。

您可以在Docker Compose文件中使用此图像,如下所示:

version: '3'

services:
  example-service:
    image: imagename:latest

答案 1 :(得分:0)

您需要使用docker build构建映像。 Docker swarm不能与标签一起识别图像。相反,它会在执行堆栈部署时记住图像的图像ID(哈希),因为标记可能会在以后更改,但哈希永远不会更改。

因此,您应该引用docker image ls所示的图像哈希,以便docker swarm不会尝试在某个注册表中找到您的图像。

version: '3'

services:
  example-service:
    image: imagename:97bfeeb4b649

答案 2 :(得分:0)

在更新本地图像时,将出现以下错误

image IMAGENAME:latest could not be accessed on a registry to record
its digest. Each node will access IMAGENAME:latest independently,
possibly leading to different nodes running different
versions of the image.

要解决此问题,请按以下步骤强制启动服务

docker service update --image IMAGENAME:latest  --force  Service Name

在上面的示例中为

docker服务更新--image imagename:97bfeeb4b649 --force服务名称