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

查看:51
本文介绍了在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的角度来看,我认为您可以执行此操作的最佳方法(无需在本地运行网络 保存 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:

缓存可配置中列出的所有目录并使用安全且受保护的网址将其上传到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天全站免登陆