在 Travis CI 上缓存 docker 图像 [英] Cache docker images on Travis CI

查看:19
本文介绍了在 Travis CI 上缓存 docker 图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在 Travis CI 上缓存 docker 图像?尝试使用 travis.yml 中的 cache.directories 缓存 /var/lib/docker/aufs/diff 文件夹和 /var/lib/docker/repositories-aufs 文件似乎不起作用,因为它们需要 root.

Is it possible to cache docker images on Travis CI? Attempting to cache the /var/lib/docker/aufs/diff folder and /var/lib/docker/repositories-aufs file with cache.directories in the travis.yml doesn't seem to work since they require root.

推荐答案

从 Docker 的角度来看,我认为你可以做到这一点的最好方法(没有运行网络本地的可能性 registry) 是 save Docker 映像并缓存导出的 tar 球.您需要在开始时 load而不是 pull 图像.这样你就不会弄乱 docker 存储实现.

From a Docker perspective, I think the best way you could do this (without the possibility of running a network local registry) is save the Docker image and cache the exported tar ball. You would need to load that at the start rather than pull an image. This way you're not messing with docker storage implementations.

install:
- docker pull busybox
- docker save busybox | gzip > docker/busybox.tar.gz
cache:
  directories:
  - docker

然后您需要在 Travis 运行之前加载缓存的图像.

You would then need to load the cached image before your Travis run.

before_script:
- gzip -dc docker/busybox.tar.gz | docker load

我不清楚 Travis 是否需要在第一次之后停止运行 install 步骤.您不希望 Travis 每次缓存后都提取和导出图像.我不确定是否有 cache 指令会自动为您做到这一点?

The bit I'm not clear on for Travis, is if you need to stop it from running the install step after the first time. You don't want Travis pulling and exporting the image each time once it's cached. I'm not sure if having the cache directive automatically does that for you?

那么主要的问题是这是否真的会比拉动图像更快:

The main question then is whether this is actually going to be any quicker than pulling the image or not:

缓存会压缩配置中列出的所有目录并使用安全且受保护的 URL 将它们上传到 S3,确保上传档案的安全性和隐私性.

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.

请注意,这使我们的缓存不是网络本地的,它仍然绑定到S3 的网络带宽和 DNS 解析.这会影响你可以而且应该存储在缓存中.如果您存储的档案大于缓存中有几百兆字节,您不太可能看到速度大幅提升.

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 基础设施中提取压缩图像.也许要求他们提供 本地缓存 Docker 图像的功能,类似于他们为 apt 包所做的,虽然听起来并不乐观.

You might just be adding overhead. As the Docker registry is backed by Cloudfront, Travis is already pulling compressed images from local, or at least close Amazon infrastructure. Maybe ask them for the feature to cache Docker images natively, similar to what they do for apt packages, although it doesn't sound hopeful.

这篇关于在 Travis CI 上缓存 docker 图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆