Skip to content

apk-no-cache

Dockerfileperformanceno fixdefault: offdockerfile/hadolint

Reports an apk add without the --no-cache flag. A RUN with a --mount of type cache or tmpfs on /var/cache/apk is not reported, since nothing is stored in the image there.

Without --no-cache, apk add keeps the downloaded package index in /var/cache/apk. That copy is written into the layer and stays in the image, making it larger for data nobody reads at run time.

--no-cache fetches the index for this one command and stores nothing; it replaces the older pair apk update and rm -rf /var/cache/apk/*.

Reported
FROM alpine:3
RUN apk add curl
RUN apk add --no-cache curl=8.5.0-r0
RUN apk add --no-cache --virtual .deps gcc=13.2.1-r0 musl-dev=1.2.4-r2
RUN apk add --no-cache ./pkg.apk
...
dockerfile:
lint:
rules:
apk-no-cache: warn # off (default), warn, error

Enabled by the presets: dockerfile/hadolint.

Suppress one line with sudsy-disable-next-line apk-no-cache in a comment of the file’s language.

The same check in other tools; Sudsy reports what each upstream rule reports.

Tool Rule Match
hadolint DL3019 full