Here is an important part of 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
As you can see there are some errors, but for some reason docker considered that both commands ended with success: #6 DONE 32.3s
.
This corrupted my Docker cache and created problems on build machine.
Question
Now question is not how to fix this step, this is cover by other SO questions (other).
How I can prevent this problem and force apt-get
to report error (none zero exit code). In my case problem was temporary network problem and this corrupted docker cache. I’ve cleared cached to fix the issue, but how to prevent this problem to repeat in a future?
2
Answers
Those are not considered errors, but Warnings, as you can see by the
W
in front of the line.You can make
apt-get update
fail hard with adding the following-o APT::Update::Error-Mode=any
Any failling commad on a POSIX operating system (linux, unix….) returns a code, 0 for success anything else for error.
This value is stored in the ‘$?’ variable, but you can directly branch off your shell script with || for or and && for an and.
the e gives you all kinds of formatting options color, bold, underscore etc… https://misc.flogisoft.com/bash/tip_colors_and_formatting