Skip to main content
Suggests using BuildKit cache mounts for package-manager install/build commands.

Description

Flags RUN instructions that install dependencies or build artifacts with package managers but do not use cache mounts. The rule follows Docker’s official cache-mount guidance in the Use cache mounts section: It also supports pnpm, uv, and bun package install flows. Each suggested mount includes an id for observability and reusability across build stages.

Detected Commands and Cache Targets

Cache path resolution from environment variables

The rule resolves custom cache paths from ENV instructions in the Dockerfile: If the variable value contains $ (unresolved shell reference), the override is skipped.

Examples

Before (violation)

After (fixed with —fix —fix-unsafe)

pnpm with PNPM_HOME

becomes:

Heredoc RUN support

becomes:

What this rule removes (and why)

This cleanup only happens when the fix adds cache mounts for the related package manager. The motivation is simple: these commands/flags either delete local package caches or explicitly disable caching, which cancels out the speed benefits of cache mounts.

Cache-cleaning commands removed

  • apt/apt-get: apt-get clean, apt clean, and rm -rf /var/lib/apt/lists*
  • apk: apk cache clean ... and rm -rf /var/cache/apk*
  • dnf: dnf clean ... and rm -rf /var/cache/dnf*
  • yum: yum clean ... and rm -rf /var/cache/yum*
  • zypper: zypper clean ... and rm -rf /var/cache/zypp*
  • npm: npm cache clean ...
  • pnpm: pnpm store prune
  • pip: pip cache purge, pip cache remove ...
  • bundle: bundle clean ...
  • yarn: yarn cache clean ...
  • dotnet: dotnet nuget locals ... --clear
  • composer: composer clear-cache, composer clearcache
  • uv: uv cache clean, uv cache prune
  • bun: bun pm cache rm, bun pm cache clean

Cache-disabling flags removed

  • apk: --no-cache
  • pip: --no-cache-dir
  • uv: --no-cache
  • bun: --no-cache

Cache-disabling environment variables removed

  • pip: ENV PIP_NO_CACHE_DIR=... (the entire ENV instruction is removed if it only sets PIP_NO_CACHE_DIR; otherwise, only the PIP_NO_CACHE_DIR variable is removed)
  • uv: ENV UV_NO_CACHE=... (the entire ENV instruction is removed if it only sets UV_NO_CACHE; otherwise, only the UV_NO_CACHE variable is removed)

References