gcloud重建了完整的容器,但Dockerfile相同,只是脚本已更改 [英] gcloud rebuilds complete container but Dockerfile is the same, only the script has changed

查看:80
本文介绍了gcloud重建了完整的容器,但Dockerfile相同,只是脚本已更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用gcloud构建Docker容器:

I am building Docker containers using gcloud:

gcloud builds submit --timeout 1000 --tag eu.gcr.io/$PROJECT_ID/dockername Dockerfiles/folder_with_dockerfile

Dockerfile的最后2个步骤包含以下内容:

The last 2 steps of the Dockerfile contain this:

COPY script.sh .
CMD bash script.sh

我要测试的许多更改都在脚本中.因此,Dockerfile保持完整.使用Docker-compose在Linux上构建这些Docker文件的结果非常快速,因为它没有检测到任何变化.但是,在gcloud上执行此操作后,我注意到整个Docker正在重新生成,而script.sh中只做了很小的更改.

Many of the changes I want to test are in the script. So the Dockerfile stays intact. Building those Docker files on Linux with Docker-compose results in a very quick build because it detects nothing has changed. However, doing this on gcloud, I notice the complete Docker being re-generated whereas only a minor change in the script.sh has been created.

有什么办法可以防止这种行为?

Any way to prevent this behavior?

推荐答案

您的本地构建速度很快,因为您已经在本地缓存了所有远程资源.

Your local build is fast because you already have all remote resouces cached locally.

看起来像使用kaniko-cache可以大大加快构建速度.(请参见 https://cloud.google.com/cloud-build/docs/kaniko-cache#kaniko-build ).

Looks like using kaniko-cache would speed a lot your build. (see https://cloud.google.com/cloud-build/docs/kaniko-cache#kaniko-build).

要在项目运行中启用缓存

To enable the cache on your project run

gcloud config set builds/use_kaniko True

第一次构建容器时,它将填充高速缓存(默认情况下为6h),其余时间将更快,因为将对依赖项进行高速缓存.

The first time you build the container it will feed the cache (for 6h by default) and the rest will be faster since dependencies will be cached.

如果您需要进一步加快构建速度,我将使用两个容器,并在本地GCP容器注册表中同时包含 :

If you need to further speed up your build, I would use two containers and have both in my local GCP container registry:

  • 第一个作为具有 all 远程依赖项(OS/语言/框架/等)的缓存.
  • 第二个是您需要的,只需使用缓存容器作为基础的COPY和CMD.
  • The fist one as a cache with all remote dependencies (OS / language / framework / etc).
  • The second one is the one you need with just the COPY and CMD using the cache container as base.

这篇关于gcloud重建了完整的容器,但Dockerfile相同,只是脚本已更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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