我在 travis-ci 上缓存了一个 docker 镜像。 docker 镜像是从 dockerfile 创建的。现在我的 dockerfile 发生了变化,我需要删除缓存并重建 docker 镜像。如何删除 travis-ci 上的缓存?
我当前的 .travis.yml
如下所示:
language: C
services:
- docker
cache:
directories:
- docker_cache
before_script:
- |
echo Now loading...
filename=docker_cache/saved_images.tar
if [[ -f "$filename" ]]; then
echo "Got one from cache."
docker load < "$filename"
else
echo "Got one from scratch";
docker build -t $IMAGE .
docker save -o "$filename" $IMAGE
fi
script:
- docker run -it ${IMAGE} /bin/bash -c "pwd"
env:
- IMAGE=test04
最佳答案
每the docs共有三种方法:
- 使用用户界面:存储库页面上的“更多选项”->“缓存”
- 使用 CLI:
travis cache --delete
- 使用API :
删除/repos/{repository.id}/caches
也就是说,Docker 镜像是明确称为 thing not to cache 的示例之一。 :
Large files that are quick to install but slow to download do not benefit from caching, as they take as long to download from the cache as from the original source
在您的示例中,不清楚 Dockerfile 之外的管道中涉及哪些内容 - 即使文件本身没有更改,任何进入其中的内容(基本镜像、源代码、等)可能有。缓存图像意味着您可能会得到误报,即使 docker build 会失败,构建也会通过。
关于docker - 如何删除 Travis CI 上的缓存?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66709707/