docker - 为什么我的 Docker 镜像中的大文件每次都被推送,即使没有对它们进行任何更改?

标签 docker

我有一个使用 Dockerfile 构建的 docker 镜像。

dockerfile 包含一些 COPY 语句。其中之一是一个大约 120MB 的大文件。

它以 COPY myfile/data/的形式编写

当我执行 docker push 到远程注册表时,每次都需要很长时间。尽管这个文件没有改变。它似乎仍然上传略多于 120MB。

我是否误解了算法如何工作以确定文件是否已更改或其他内容?

docker build 如何处理通配符? IE。

复制本地目录/*/远程目录/

这实际上是一个纯数据卷。但我不确定这是最好的方法。鼓励仅数据卷,但我几乎在考虑将文件上传到运行 sftp 的仅数据卷,然后再上传文件可能是更好的方法。它是一个引导服务器,这些是 Linux initrd 和内核文件。我没有很多,但希望保留一些,并将删除旧的。

更新:
我想我可能发现了一个与 docker build 计算文件更改方式相关的错误。查看我的 github 问题 here .

最佳答案

docker documentation状态:

In the case of the ADD and COPY instructions, the contents of the file(s) being put into the image are examined. Specifically, a checksum is done of the file(s) and then that checksum is used during the cache lookup. If anything has changed in the file(s), including its metadata, then the cache is invalidated.



即使文件内容没有改变,文件元数据的改变也会导致缓存失效。所以我猜你的文件的权限或创建/更新日期在你的 docker build 运行之间发生了变化。

关于docker - 为什么我的 Docker 镜像中的大文件每次都被推送,即使没有对它们进行任何更改?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29662354/

相关文章:

docker - CentOS 8 : Problem: package docker-ce-xxxxxx. x86_64 需要 containerd.io >= 1.4.1

macos - 如何从不同的 VM 连接到 Docker 实例

ruby-on-rails - 在更新dockerfile之后重新创建容器

docker - 使用 docker run 将值连接到现有的环境变量

azure - Docker 文件错误!错误: Specify a project or solution file.当前工作目录不包含项目或解决方案文件

oracle - 如何强制 flyway 清理我的 docker oracle 数据库?

docker - wget在Docker容器中失败,并且似乎HTTP代理在Centos 7.3中不起作用

r - 如何修复在 ShinyProxy 中获取 CSS 和 Javascript 文件时出现的 '404 (Not Found)' 错误

docker 不保留状态

php - 将 Xdebug 从 php-fpm 和 nginx 容器中分离出来