apt-get更新失败,但退出状态仍然是成功,这破坏了我的docker缓存



这里是docker构建日志的一个重要部分

#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缓存。我已经清除了cached来解决这个问题,但如何防止这个问题在将来再次发生?

这些不被视为错误,而是警告,正如您可以从行前面的W中看到的那样。

添加以下-o APT::Update::Error-Mode=any可以使apt-get update发生硬故障

POSIX操作系统(linux、unix…(上的任何故障命令都会返回一个代码,0表示成功,其他任何错误都表示错误。

此值存储在"$?"中变量,但您可以直接用|| for或和&对于和。

apt upgrade || echo "e[31mERROR running APT !e[0m"

e为您提供了各种格式选项颜色、粗体、下划线等。。。https://misc.flogisoft.com/bash/tip_colors_and_formatting

最新更新