gpt4 book ai didi

Docker Swarm 部署本地 Dockerfile

转载 作者:行者123 更新时间:2023-12-02 18:02:21 28 4
gpt4 key购买 nike

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

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

最佳答案

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

Note: This option is ignored when deploying a stack in swarm mode with a (version 3) Compose file. The docker stack command accepts only pre-built images. - from docker docs

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

docker build -t imagename --no-cache .

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

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

version: '3'

services:
example-service:
image: imagename:latest

关于Docker Swarm 部署本地 Dockerfile,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49356099/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com