强制docker构建仅一步一步``重建'' [英] force a docker build to 'rebuild' a single step

查看:90
本文介绍了强制docker构建仅一步一步``重建''的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道docker有一个-no-cache = true 选项可以强制构建一个干净的docker镜像.但是对我来说,我真正想做的就是强制最后一步在我的dockerfile中运行,这是一个运行shell脚本的 CMD 命令.

I know docker has a --no-cache=true option to force a clean build of a docker image. For me however, all I'd really like to do is force the last step to run in my dockerfile, which is a CMD command that runs a shell script.

无论出于何种原因,当我修改该脚本并将其保存时,典型的docker构建都将重用该步骤的缓存版本.有没有办法强迫docker不要只在那一部分上这样做?

For whatever reason, when I modify that script and save it, a typical docker build will reuse the cached version of that step. Is there a way to force docker not to do so, just on that one portion?

推荐答案

请注意,这将使该行之后 all Dockerfile指令的缓存无效.这是 1996年问题(尚未实施)中所要求的.

Note that this would invalidate the cache for all Dockerfile directives after that line. This is requested in Issue 1996 (not yet implemented).

当前解决方法是:

FROM foo
ARG CACHE_DATE=2016-01-01
<your command without cache>

docker build --build-arg CACHE_DATE=$(date) ....

这将使每个版本的 ARG CACHE_DATE 行之后的缓存失效.

That would invalidate cache after the ARG CACHE_DATE line for every build.

="a href =" https://stackoverflow.com/users/1850609/acdcjunior> acdcjunior 报告-docker-build-to-rebuild-a-step/37018862?noredirect = 1#comment114435305_37018862>评论必须使用:

acdcjunior reports in the comments having to use:

docker build --build-arg CACHE_DATE=$(date +%Y-%m-%d_%H:%M:%S)

这篇关于强制docker构建仅一步一步``重建''的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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