在Docker舊版Debian裡安裝套件 / How to Handle the “Failed to fetch” Error When Running “apt-get update”

在現今2024年的時候,上面的作業系統已經不在支援列表了。

因此當我們直接執行「apt-get update」的時候,就會看到以下錯誤訊息:

Reading package lists...
W: The repository 'http://security.debian.org/debian-security stretch/updates Release' does not have a Release file.
W: The repository 'http://deb.debian.org/debian stretch Release' does not have a Release file.
W: The repository 'http://deb.debian.org/debian stretch-updates Release' does not have a Release file.
E: Failed to fetch http://security.debian.org/debian-security/dists/stretch/updates/main/binary-amd64/Packages  404  Not Found
E: Failed to fetch http://deb.debian.org/debian/dists/stretch/main/binary-amd64/Packages  404  Not Found
E: Failed to fetch http://deb.debian.org/debian/dists/stretch-updates/main/binary-amd64/Packages  404  Not Found
E: Some index files failed to download. They have been ignored, or old ones used instead.

https://stackoverflow.com/a/76095392

Alain Hernandez為Docker的使用者提供了一套解法。請在執行「apt-get update」之前,加上以下程式碼,以此修改更新網址

#Update stretch repositories
RUN sed -i s/deb.debian.org/archive.debian.org/g /etc/apt/sources.list
RUN sed -i 's|security.debian.org|archive.debian.org/|g' /etc/apt/sources.list
RUN sed -i '/stretch-updates/d' /etc/apt/sources.list

上述的做法是把更新網址從與原本的「security」改成了「archive」,這樣即使系統無法安裝最新版套件,至少也還能安裝之前的套件。

Leave a Comment

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *