My understanding is that if the RUN
command "string" itself just does not change (i.e., the list of packages to be installed does not change), docker engine uses the image in the cache for the same operation. This is also my experience:
...
Step 2/6 : RUN apt update && DEBIAN_FRONTEND=noninteractive apt install -y curl git-all locales locales-all python3 python3-pip python3-venv libusb-1.0-0 gosu && rm -rf /var/lib/apt/lists/*
---> Using cache
---> 518e8ff74d4c
...
However, the official Dockerfile best practices document says this about apt-get:
Using
RUN apt-get update && apt-get install -y
ensures your Dockerfile installs the latest package versions with no further coding or manual intervention. This technique is known as “cache busting”.
This is true if I add a new package to the list but it is not if I do not modify the list.
Is my understanding correct, or I am missing something here?
If yes, can I assume that I will only get newer packages in apt-get install
if also the Ubuntu base image has been updated (which invalidates the whole cache)?