如果映像存在,泊坞窗可以跳过构建吗? [英] Can docker compose skip build if the image is present?

查看:65
本文介绍了如果映像存在,泊坞窗可以跳过构建吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以以仅在存储库中不存在映像的情况下构建 docker-compose up 的方式运行?

Is it possible to run docker-compose up in such a way that it will only build if the image isn't present in the repository?

我正在测试一种可在两种不同环境中运行的测试方案:本地在笔记本电脑上,以及在服务器上作为测试自动化的一部分。我的docker-compose文件看起来像这样:

I'm working on a test scenario that will run in two different environments: locally on a laptop, and on a server as part of test automation. My docker-compose file looks something like this:

services:
  my-service1:
    build: "./local-repo1"
    image: "image1"
  my-service2:
    build: "./local-repo2"
    image: "image2"
  ...

如果我在本地本地目录中本地运行它,则运行良好。如果我尝试在从docker存储库中提取的服务器上运行它,则会抱怨找不到构建路径。如果我删除了 build 属性,则它可以在服务器上正常运行,但是除非我事先构建映像,否则它不会在本地运行。

If I run it locally where the local-repo directories exist it runs fine. If I try to run it on the server where it instead pulls from a docker repository it complains that it cannot find the build path. If I take out the build property it runs fine on the server, but then it won't run locally unless I build the images beforehand.

是否有一种方法可以使它仅在图像不存在时尝试构建?如果不是,我可以尝试一些解决方法,但我更希望仅使用一个处理每种情况的docker-compose文件。

Is there a way to make it only try to build if the image doesn't already exist? If not I can try some workarounds, but I'd prefer to use just one docker-compose file that handles each case.

推荐答案

您可以使用 docker-compose pull 来获取图像。然后,如果它们已经存在,则Compose不会尝试再次构建它们。

You can use docker-compose pull to fetch images. Then if they are present already, Compose will not try to build them again.

要确保避免重建,可以使用-没有构建

To be really sure to avoid rebuilds, you can use --no-build.

docker-compose pull
docker-compose up -d --no-build

您真正的问题是您正在指定构建上下文,但是随后尝试使用

Your real problem is that you are specifying a build context, but then trying to use docker-compose without that build context being present.

当docker-compose运行时,即使没有计划进行构建,将验证构建上下文至少存在。如果不是这样,它将失败。

When docker-compose runs, even if it has no plan to do a build, it will verify the build context at least exists. If it doesn't, then it will fail.

要满足此要求,您需要做的就是为任何缺少的构建上下文创建一个空目录。

All you need to do to satisfy this requirement is create an empty directory for any missing build context. That should make docker-compose happy enough to run.

mkdir -p local-repo1 local-repo2

这篇关于如果映像存在,泊坞窗可以跳过构建吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆