是否可以在 Travis CI 上缓存 docker 图像?尝试使用 travis.yml 中的 cache.directories 缓存 /var/lib/docker/aufs/diff
文件夹和 /var/lib/docker/repositories-aufs
文件似乎不起作用,因为它们需要 root。
最佳答案
从 Docker 的角度来看,我认为最好的方法是 registry (不可能在本地运行网络 save
) Docker 镜像并缓存导出的 tar 球。您需要 load
在开始时而不是 pull
图像。这样你就不会弄乱 docker 存储实现。
install:
- docker pull busybox
- docker save busybox | gzip > docker/busybox.tar.gz
cache:
directories:
- docker
然后您需要在 Travis 运行之前加载
缓存的图像。
before_script:
- gzip -dc docker/busybox.tar.gz | docker load
我不清楚 Travis 是否需要在第一次之后停止运行 install
步骤。您不希望 Travis 每次缓存后都提取和导出图像。我不确定是否有 cache
指令会自动为您做到这一点?
那么主要的问题是这是否真的会比拉动图像更快:
The caching tars up all the directories listed in the configuration and uploads them to S3, using a secure and protected URL, ensuring security and privacy of the uploaded archives.
Note that this makes our cache not network-local, it’s still bound to network bandwidth and DNS resolutions for S3. That impacts what you can and should store in the cache. If you store archives larger than a few hundred megabytes in the cache, it’s unlikely that you’ll see a big speed improvement.
您可能只是增加了开销。由于 Docker 注册表由 Cloudfront 提供支持,Travis 已经从本地或至少关闭 Amazon 基础设施中提取压缩图像。也许向他们询问 cache Docker images natively 的功能,类似于他们对 apt
包所做的,although it doesn't sound hopeful .
关于performance - 在 Travis CI 上缓存 docker 图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35305492/