Linux

無法使用 apt-cacher

  • December 28, 2021

我想apt-cacher在本地用作我的包代理。尤其是當我連續多次重建我的 Docker 映像時。我已經apt-cacher在我的系統上安裝並執行。

我將代理地址設置為:(http://melroy-pc:3142melroy-pc我的主機名)。就我而言,我創建了一個/etc/apt/apt.conf.d/02proxy文件:

Acquire::http::proxy "http://melroy-pc:3142";
Acquire::https::proxy "http://melroy-pc:3142";

(我已經嘗試只定義http::proxy(沒有 https),我也嘗試添加APT::Get::AllowUnauthenticated "true";,都沒有任何運氣)

之後我只執行我的 apt 命令(apt update & apt install)。現在導致問題:

Step 9/41 : RUN apt-get update && apt-get install -y --no-install-recommends     dirmngr gnupg gnupg-l10n     gnupg-utils gpg gpg-agent     gpg-wks-client gpg-wks-server gpgconf     gpgsm libassuan0 libksba8     libldap-2.4-2 libldap-common libnpth0     libreadline8 libsasl2-2 libsasl2-modules     libsasl2-modules-db libsqlite3-0 libssl1.1     lsb-base pinentry-curses readline-common     apt-transport-https ca-certificates curl     software-properties-common apt-utils net-tools
---> Running in af278cee1d52
Err:1 http://deb.debian.org/debian bullseye InRelease
 403  Access to cache prohibited [IP: 192.168.2.166 3142]
Err:2 http://security.debian.org/debian-security bullseye-security InRelease
 403  Access to cache prohibited [IP: 192.168.2.166 3142]
Err:3 http://deb.debian.org/debian bullseye-updates InRelease
 403  Access to cache prohibited [IP: 192.168.2.166 3142]
Reading package lists...
E: The repository 'http://deb.debian.org/debian bullseye InRelease' is not signed.
E: Failed to fetch http://deb.debian.org/debian/dists/bullseye/InRelease  403  Access to cache prohibited [IP: 192.168.2.166 3142]
E: Failed to fetch http://security.debian.org/debian-security/dists/bullseye-security/InRelease  403  Access to cache prohibited [IP: 192.168.2.166 3142]
E: The repository 'http://security.debian.org/debian-security bullseye-security InRelease' is not signed.
E: Failed to fetch http://deb.debian.org/debian/dists/bullseye-updates/InRelease  403  Access to cache prohibited [IP: 192.168.2.166 3142]
E: The repository 'http://deb.debian.org/debian bullseye-updates InRelease' is not signed.

**重要提示:**當我不使用代理時,我的軟體包都已成功安裝,沒有任何問題。

這種方法過去曾經有效,當我使用apt-key而不是gpg(我不知道它是否相關,請參閱我的另一個問題)。

正如@cas 所指出的,Docker 主機通常在另一個本地 IP 塊中使用私有 IP 地址。預設情況下,1.7.0 版之後的 apt-cacherallowed_hosts = ''用作預設值,而不是*.

我的解決方案:取消註釋allowed_hosts設置並將值*放入/etc/apt-cacher/apt-cacher.conf文件中:

allowed_hosts = *

這將允許所有 IP 地址(包括 Docker IP)。當然你也可以指定一個特定的範圍

引用自:https://unix.stackexchange.com/questions/684123