RUN --mount=type=cache
This mount type allows the build container to cache directories for compilers
and package managers.
Contents of the cache directories persists between builder invocations without
invalidating the instruction cache. Cache mounts should only be used for better
performance. Your build should work with any contents of the cache directory as
another build may overwrite the files or GC may clean it if more storage space
is needed.
Apt needs exclusive access to its data, so the caches use the optionsharing=locked, which will make sure multiple parallel builds using
the same cache mount will wait for each other and not access the same
cache files at the same time. You could also usesharing=privateif
you prefer to have each build create another cache directory in this
case.