5/24/2025 at 7:28:41 AM
RUN --mount=type=cache can also significantly reduce build times if there is inter-build locality; i.e. if container build jobs run on the same nodes so that cache mounts can be reused by subsequent build jobs.Examples of docker image cache mounts:
# yum + dnf
RUN --mount=type=cache,id=yum-cache,target=/var/cache/yum,sharing=shared \
--mount=type=cache,id=dnf-cache,target=/var/cache/dnf,sharing=shared \
# apt
RUN --mount=type=cache,id=aptcache,target=/var/cache/apt,sharing=shared
# pip
RUN --mount=type=cache,id=pip-cache,target=${apphome}/.cache/pip,sharing=shared \
# cargo w/ uid=1000
RUN --mount=type=cache,id=cargocache,target=${apphome}/.cargo/registry,uid=1000,sharing=shared \
"Optimize cache usage in builds" https://docs.docker.com/build/cache/optimize/
by westurner