Why this matters
Avoids shipping unnecessary toolchains and reduces image size and CVE surface.
If a single-stage image must build native deps, remove compilers/headers after install and clear package caches in the same layer.
Avoids shipping unnecessary toolchains and reduces image size and CVE surface.
Side-by-side examples engineers can pattern-match during review.
RUN apk add --no-cache build-base python3 && npm ci
# toolchain left installedRUN apk add --no-cache build-base python3 \
&& npm ci \
&& apk del build-base python3 \
&& rm -rf /var/cache/apk/*apt-get install build-essential && npm ciapt-get update && apt-get install ... && npm ci && apt-get purge -y ... && rm -rf /var/lib/apt/lists/*From the same buckets as this rule.