這里是 docker build log 的重要部分
#6 [stage-1 2/20] RUN apt-get -y update && apt-get -y upgrade
#6 sha256:6a65c591472319f4cf0c6954f890ee1d5e465b9b12670d78dd15e738cf4bd37d
#6 31.57 Err:1 http://archive.ubuntu.com/ubuntu focal InRelease
#6 31.57 Could not connect to archive.ubuntu.com:80 (91.189.88.142), connection timed out Could not connect to archive.ubuntu.com:80 (91.189.88.152), connection timed out
#6 31.57 Err:2 http://archive.ubuntu.com/ubuntu focal-updates InRelease
#6 31.57 Unable to connect to archive.ubuntu.com:http:
#6 31.57 Err:3 http://archive.ubuntu.com/ubuntu focal-backports InRelease
#6 31.57 Unable to connect to archive.ubuntu.com:http:
#6 32.00 Err:4 http://security.ubuntu.com/ubuntu focal-security InRelease
#6 32.00 Could not connect to security.ubuntu.com:80 (91.189.88.152), connection timed out Could not connect to security.ubuntu.com:80 (91.189.91.39), connection timed out Could not connect to security.ubuntu.com:80 (91.189.88.142), connection timed out Could not connect to security.ubuntu.com:80 (91.189.91.38), connection timed out
#6 32.02 Reading package lists...
#6 32.04 W: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/focal/InRelease Could not connect to archive.ubuntu.com:80 (91.189.88.142), connection timed out Could not connect to archive.ubuntu.com:80 (91.189.88.152), connection timed out
#6 32.04 W: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/focal-updates/InRelease Unable to connect to archive.ubuntu.com:http:
#6 32.04 W: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/focal-backports/InRelease Unable to connect to archive.ubuntu.com:http:
#6 32.04 W: Failed to fetch http://security.ubuntu.com/ubuntu/dists/focal-security/InRelease Could not connect to security.ubuntu.com:80 (91.189.88.152), connection timed out Could not connect to security.ubuntu.com:80 (91.189.91.39), connection timed out Could not connect to security.ubuntu.com:80 (91.189.88.142), connection timed out Could not connect to security.ubuntu.com:80 (91.189.91.38), connection timed out
#6 32.04 W: Some index files failed to download. They have been ignored, or old ones used instead.
#6 32.06 Reading package lists...
#6 32.08 Building dependency tree...
#6 32.08 Reading state information...
#6 32.08 Calculating upgrade...
#6 32.08 0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
#6 DONE 32.3s
如您所見,有一些錯誤,但出于某種原因,docker 認為這兩個命令都以成功結束:#6 DONE 32.3s.
這破壞了我的 Docker 快取并在構建機器上產生了問題。
題
現在的問題不是如何解決此步驟,其他 SO 問題(其他)涵蓋了這一點。
如何防止此問題并強制apt-get報告錯誤(無零退出代碼)。在我的情況下,問題是臨時網路問題和這個損壞的 docker 快取。我已清除快取以解決此問題,但如何防止此問題在未來重復出現?
uj5u.com熱心網友回復:
這些不被視為錯誤,而是警告,正如您W在行前看到的那樣。
您可以apt-get update通過添加以下內容來使失敗變得困難-o APT::Update::Error-Mode=any
uj5u.com熱心網友回復:
POSIX 作業系統(linux、unix ....)上的任何失敗的命令都會回傳一個代碼,0 表示成功,其他任何表示錯誤。
此值存盤在“$?”中 變數,但您可以使用 || 直接分支您的 shell 腳本 for or and && for an and。
apt upgrade || echo "\e[31mERROR running APT \!\e[0m"
\e 為您提供各種格式選項顏色、粗體、下劃線等... https://misc.flogisoft.com/bash/tip_colors_and_formatting
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/435037.html
