Skip to content

Docker

Cache mount

This helps speed up subsequent docker builds by caching intermediate files and reusing them across builds. It's available with docker buildkit. The key here is to disable anything that could delete the cache, because we want to preserve it. The cache mount is not going to end up in the docker image being built, so there's no concern about disk space usage.

Put this flag between RUN and the command

RUN \
--mount=type=cache,target=/root/.cache
  pip install -r requirements.txt

For pip, the files are by default stored in /root/.cache/pip. Pip caching docs

For apk, the cache directory is /var/cache/apk/. APK wiki on local cache

For apt, the cache directory is /var/cache/apt/.

References