我正在处理一些不太可靠的规范存储库的企业镜像。所谓不可靠,是指我在尝试在基于 ubuntu:20.04 的 docker 镜像中安装几个软件包时遇到 404 和 502 错误。
我创建了以下/etc/apt/apt.conf.d/99custom
文件:
Acquire::Retries "3";
Acquire::https::Timeout "240";
APT::Get::Assume-Yes "true";
APT::Install-Recommends "false";
APT::Install-Suggests "false";
Debug::Acquire::https "true";
它确实按预期处理了 502 错误:
#12 12.65 GET /ubuntu_debian_valid_internet/pool/main/p/python3-defaults/python3-minimal_3.8.2-0ubuntu2_amd64.deb HTTP/1.1
#12 15.17 Answer for: https://.../ubuntu_debian_valid_internet/pool/main/p/python3-defaults/python3-minimal_3.8.2-0ubuntu2_amd64.deb
#12 15.17 HTTP/1.1 502 Bad Gateway
#12 142.3 GET /ubuntu_debian_valid_internet/pool/main/p/python3-defaults/python3-minimal_3.8.2-0ubuntu2_amd64.deb HTTP/1.1
#12 144.4 Answer for: https://.../ubuntu_debian_valid_internet/pool/main/p/python3-defaults/python3-minimal_3.8.2-0ubuntu2_amd64.deb
#12 144.4 HTTP/1.1 200 OK
#12 144.4 Date: Thu, 11 Aug 2022 07:46:23 GMT
#12 144.4 Content-Type: application/x-debian-package
但似乎对于 404 错误(我可能会遇到一些,如果我稍后重试,它会起作用),没有自动重试。这是预期的行为吗?当然我可以(事实上我确实这样做了)将我的 apt update / install 包装在循环中以强制重试,但这似乎是一种黑客行为:
&& while !\
apt update \
;do echo "apt update has failed... Waiting before next try"; sleep 1; done\
&& while !\
apt install\
curl \
apt-utils \
iputils-ping \
nano \
gridsite-clients\
cppcheck \
...
npm \
;do echo "apt install has failed... Waiting before next try"; sleep 1; done\