Skip to content

.tip

· one of the small things

Cache the package manager's store across builds with a mount

A layer cache is all or nothing. Change the lockfile and the whole install runs again from the network. A cache mount keeps the store around between builds.

RUN --mount=type=cache,id=pnpm,target=/root/.local/share/pnpm/store \
    pnpm install --frozen-lockfile

The install still runs, but it links from the local store instead of downloading everything. The same trick works for the pip, cargo and go caches.

dockerci