apt 更新 Dockerfile 和提示中的不同行為,回傳錯誤代碼 100 但有效

apt 更新 Dockerfile 和提示中的不同行為,回傳錯誤代碼 100 但有效

我正在嘗試在 Microsoft azure function docker 上安裝 apt 來源,這是我的 Dockerfile

FROM mcr.microsoft.com/azure-functions/python:3.0-python3.9

RUN echo 'deb [trusted=yes] http://deb.debian.org/debian testing main' > /etc/apt/sources.list.d/testing.list
RUN apt update -y

apt update -y步驟失敗並出現以下錯誤

WARNING: apt does not have a stable CLI interface. Use with caution in scripts.

Get:1 http://deb.debian.org/debian buster InRelease [122 kB]
Get:2 http://security.debian.org/debian-security buster/updates InRelease [65.4 kB]
Hit:3 http://security.debian.org/debian-security jessie/updates InRelease
Get:4 http://deb.debian.org/debian buster-updates InRelease [51.9 kB]
Get:5 https://packages.microsoft.com/debian/9/prod stretch InRelease [4009 B]
Get:6 http://deb.debian.org/debian testing InRelease [112 kB]
Get:7 https://packages.microsoft.com/debian/9/prod stretch/main amd64 Packages [161 kB]
Get:8 http://deb.debian.org/debian testing/main amd64 Packages [8248 kB]
Reading package lists...
E: Repository 'http://security.debian.org/debian-security buster/updates InRelease' changed its 'Suite' value from 'stable' to 'oldstable'
E: Repository 'http://deb.debian.org/debian buster InRelease' changed its 'Suite' value from 'stable' to 'oldstable'
E: Repository 'http://deb.debian.org/debian buster-updates InRelease' changed its 'Suite' value from 'stable-updates' to 'oldstable-updates'
The command '/bin/sh -c apt update -y' returned a non-zero code: 100

但:

  • 如果我在啟動後運行完全相同的兩個命令docker run --rm -it --entrypoint bash mcr.microsoft.com/azure-functions/python:3.0-python3.9apt update -y工作正常,
  • 如果我更改映像所基於的基礎映像debian:buster-slim,docker建置工作正常,
  • 即使命令失敗,我也可以從 中安裝軟體包testing,例如,apt update -y || apt install g++將在 Buster 上安裝g++-10而不是預設安裝。g++-8

知道命令失敗的原因嗎?我該如何解決它?


編輯:在 dockerfile 中添加解決--allow-releaseinfo-changeapt update -y問題,但我仍然想知道為什麼它失敗了沒有?


筆記:問題從 SO 轉移,因為它顯然是偏離主題的……讓我知道這裡是否也是偏離主題的。

答案1

長話短說

根本問題是您正在使用的基礎映像中的錯誤。永久修復方法是清除/var/lib/apt/lists基礎映像中的 Dockerfile,但可以透過重建基礎映像或使用 選項來暫時解決問題--allow-releaseinfo-change

docker build和之間此行為不同的原因docker run -it是使用-t標誌來分配 tty。這改變了apt -y( )的行為APT::Get::Assume-Yes

完整解釋

儲存庫...更改了其“套件”值

在以下情況下會出現此錯誤:

  1. APT 有一個 Release 檔案的快取版本——這就是錯誤。 Docker 基礎映像通常應該清理這個快取。
  2. 遠端倉庫有較新版本
  3. 兩個版本之間的某些欄位不匹配

在非docker環境中,這項檢查的目的是防止使用者突然意外地安裝來自不同 Debian 版本的軟體包。

在這種情況下,基礎圖像mcr.microsoft.com/azure-functions/python:3.0-python3.9 包含Debian buster 發布檔案的快取版本(條件#1)與Suite: stable,因為它在建構時是當前的。

然而,主副本中Debian 存檔較新(條件#2),現在有了Suite: oldstable(條件#3),因為 Debian 10 buster 已經被取代由 Debian 11 bullseye 提供。

因此,當您嘗試apt update在此基礎映像上運行時,它會失敗,因為不匹配舊的快取版本和當前版本之間。

我剛剛嘗試了你的 Dockerfile(2021-09-03),它對我來說工作正常。這可能是因為自從您發布此問題以來它已被重建。這將導致它緩存 Debian 存檔中的新版本文件,從而糾正不匹配的情況(上面的 #2/#3 不再成立)。

但是,您可以驗證該錯誤是否仍然存在:

$ docker run --rm -it --entrypoint bash mcr.microsoft.com/azure-functions/python:3.0-python3.9               
root@722ec78233b4:/# grep Suite /var/lib/apt/lists/*Release
/var/lib/apt/lists/deb.debian.org_debian_dists_buster-updates_InRelease:Suite: oldstable-updates
/var/lib/apt/lists/deb.debian.org_debian_dists_buster_InRelease:Suite: oldstable
/var/lib/apt/lists/packages.microsoft.com_debian_9_prod_dists_stretch_InRelease:Suite: stretch
/var/lib/apt/lists/security.debian.org_debian-security_dists_buster_updates_InRelease:Suite: oldstable
/var/lib/apt/lists/security.debian.org_debian-security_dists_jessie_updates_InRelease:Suite: oldoldstable

oldoldstable並且在下一個 Debian 版本發布後,當 buster 變成而 bullseye 變成時,同樣的錯誤將會再次出現oldstable

我最近在一個不相關的 docker 基礎映像中看到了類似的問題,我認為這個錯誤相當普遍。

-y選擇權的行為

當您apt使用 tty 作為標準輸入運行時,-y將覆蓋此檢查並允許update命令成功。但是,如果沒有 tty(非互動式會話),則該-y選項不會覆蓋這張支票。我使用舊版本的錯誤圖像確認了這一點:

# aborts    
docker run --rm mcr.microsoft.com/azure-functions/python:3.0.15066-python3.9-slim apt update -y

# succeeds
docker run -t --rm mcr.microsoft.com/azure-functions/python:3.0.15066-python3.9-slim apt update -y

# prompts for y/N to continue
docker run -it --rm mcr.microsoft.com/azure-functions/python:3.0.15066-python3.9-slim apt update

# aborts
docker run --rm mcr.microsoft.com/azure-functions/python:3.0.15066-python3.9-slim apt update

相關內容