为什么我的 Docker 图像中的大文件每次都被推送,即使没有对它们进行任何更改?
Why are large files in my Docker image getting pushed each time even when no changes have been made to them?
我有一个正在使用 Dockerfile 构建的 docker 图像。
docker文件包含一些 COPY 语句。其中一个是一个大约120MB的大文件。
写成 COPY myfile /data/
当我向远程注册表执行 docker 推送时,每次都需要很长时间。尽管这个文件没有改变。它似乎仍然上传略多于 120MB。
我是否误解了算法如何确定文件是否已更改或其他内容?
docker 构建如何处理通配符?即
复制 localdir/* /remotedir/
这实际上是一个纯数据卷。但我不确定这是最好的方法。鼓励使用仅数据卷,但我几乎在考虑将文件上传到运行 sftp 的仅数据卷,然后再上传文件可能是更好的方法。它是一个引导服务器,这些是 Linux initrd 和内核文件。我没有很多,但希望保留一些,并会删除旧的。
更新:
我想我可能发现了一个与 docker 构建计算文件更改的方式相关的错误。请参阅我的 github 问题 here。
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.
即使文件内容没有改变,文件元数据的改变也会导致缓存失效。所以我猜你的文件的权限或 creation/update 日期在你的 docker 构建运行之间发生了变化。
我有一个正在使用 Dockerfile 构建的 docker 图像。
docker文件包含一些 COPY 语句。其中一个是一个大约120MB的大文件。
写成 COPY myfile /data/
当我向远程注册表执行 docker 推送时,每次都需要很长时间。尽管这个文件没有改变。它似乎仍然上传略多于 120MB。
我是否误解了算法如何确定文件是否已更改或其他内容?
docker 构建如何处理通配符?即
复制 localdir/* /remotedir/
这实际上是一个纯数据卷。但我不确定这是最好的方法。鼓励使用仅数据卷,但我几乎在考虑将文件上传到运行 sftp 的仅数据卷,然后再上传文件可能是更好的方法。它是一个引导服务器,这些是 Linux initrd 和内核文件。我没有很多,但希望保留一些,并会删除旧的。
更新: 我想我可能发现了一个与 docker 构建计算文件更改的方式相关的错误。请参阅我的 github 问题 here。
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.
即使文件内容没有改变,文件元数据的改变也会导致缓存失效。所以我猜你的文件的权限或 creation/update 日期在你的 docker 构建运行之间发生了变化。