当文件的mtime值更改并且git不跟踪文件的mtime值时,Docker使docker
build缓存无效。这种缓存失效也会在其他情况下出现,例如在持续集成或涉及docker,git和branchs的构建环境中。
在要求docker构建容器之前,我一直在运行的Makefile中使用“触摸”目标:
touch: @echo "Reset timestamps on git working directory files..." find ./ | grep -v .git | xargs touch -t 200001010000.00
接下来,始终在同一Makefile中运行
make touch,
docker build或始终在同一基于docker的“ build”目标中运行…
另一个选项是设置一个git钩子,该钩子会自动修改mtime值:https
:
//git.wiki.kernel.org/index.php/Examplescripts#Setting_the_timestamps_of_the_files_to_the_commit_timestamp_of_the_commit_which_last_touched_them
另一个可能的解决方案是派生docker并将mtime从其缓存定义中删除:https
:
//github.com/docker/docker/blob/master/pkg/tarsum/tarsum.go
注意 :从docker
1.8开始,mtime使缓存无效时不再考虑在内。拉取请求#12031更新了此行为



