注意:由于新的Docker Hub似乎支持缓存,因此我的问题似乎不再有效。我还没有亲自测试过这个。请参阅new answer below。
Docker Hub的自动构建存储库似乎不会缓存图像。在构建时,它会删除所有中间容器。这是打算工作的方式还是我做错了什么?如果没有为每一个小变化重建一切,那将是非常好的。我认为这应该是码头工人的最佳优势之一,他们的建造者没有使用它似乎很奇怪。那么为什么它不缓存图像呢?
更新: 我已经开始使用Codeship构建我的应用程序,然后在我的DigitalOcean服务器上运行远程命令来复制构建的文件并运行docker build命令。我还不确定为什么Docker Hub不会缓存。
答案 0 :(得分:25)
Disclaimer: I am a lead software engineer at Quay.io, a private Docker container registry, so this is an educated guess based on the same problem we faced in our own build system implementation.
Given my experience with Dockerfile build systems, I would suspect that the Docker Hub does not support caching because of the way caching is implemented in the Docker Engine. Caching for Docker builds operates by comparing the commands to be run against the existing layers found in memory.
For example, if the Dockerfile has the form:
FROM somebaseimage
RUN somecommand
ADD somefile somefile
Then the Docker build code will:
somebaseimage
existsRUN somecommand
whose parent is the previous imageADD somefile somefile
+ a hashing of the contents of somefile
(to make sure it is invalidated when somefile
changes), whose parent is the previous imageIf any of the above steps match, then that command will be skipped in the Dockerfile build process, with the cached image itself being used instead. However, the one key issue with this process is that it requires the cached images to be present on the build machine, in order to find and verify the matches. Having all of everyone's images on build nodes would be highly inefficient, making this a harder problem to solve.
At Quay.io, we solved the caching problem by creating a variation of the Docker caching code that could precompute these commands/hashes and then ask our registry for the cached layers, downloading them to the machine only after we had found the most efficient caching set. This required significant data model changes in our registry code.
If you'd like more information, we gave a technical overview into how we do so in this talk: https://youtu.be/anfmeB_JzB0?list=PLlh6TqkU8kg8Ld0Zu1aRWATiqBkxseZ9g
答案 1 :(得分:3)
新的Docker Hub带有支持构建缓存的新的自动构建系统。