在 Debian(以及基于 APT 的系统中)里常说的“缓存无法命中”,通常是指在 APT 包缓存 或 代理 / CDN 缓存 层面,期望的 .deb 或 Packages 文件没有被复用,而是重新下载。常见原因和排查思路如下:
如果你执行过:
apt clean
apt-get clean
会删除 /var/cache/apt/archives/*.deb,自然无法命中。
APT 缓存是按 包名 + 版本 + 架构 命中的:
apt update 后索引变化旧 deb 就不会被使用。
apt 缓存保留部分系统配置了:
APT::Keep-FDS
Dir::Cache::archives
或使用了 apt-get install --no-cache(容器常见)。
例如:
缓存不会通用。
如某些镜像:
?_autocache=123
导致 URL 变化,代理无法缓存。
https 且代理不支持缓存Cache-Control: no-storeapt update 强制校验 Release / InReleaseRUN apt-get update && apt-get install -y xxx
如果:
apt-get update 在前面✅ 推荐写法:
COPY sources.list /etc/apt/sources.list
RUN apt-get update && apt-get install -y xxx \
&& rm -rf /var/lib/apt/lists/*
--no-cachedocker build --no-cache
apt-get install -y --print-uris vim
如果输出是 copy 而不是 http,说明命中本地缓存。
curl -I http://mirror/debian/dists/stable/Release
apt clean/var/cache/aptapt-cacher-ng)如果你能说明具体场景(裸机 / Docker / CI / 代理),以及“缓存”指的是 APT 本地缓存、HTTP 代理,还是 CI 缓存,我可以给你更精确的原因和配置示例。