Skip to content

apk-pin-versions

Dockerfilesuspiciousno fixdefault: offdockerfile/hadolint

Reports an apk add that names a package without a version. A package is pinned when its name has =, ~, < or > (curl=8.5.0-r0, curl~8.5) or when it is a local .apk file; a variable such as $PKGS counts as unpinned, because its content is unknown.

The values of options that take one (--virtual NAME, -t NAME, --repository URL, -X URL) are not taken for packages, and an apk add with no package is fine.

Without a version, apk add installs whatever the Alpine repository holds on the day of the build. Rebuilding the same Dockerfile later can give an image with other package versions, and a new release that breaks your program arrives without any change on your side.

A pinned build is repeatable. The price is upkeep: when the repository replaces a version with a newer one, the build fails until you update the pin.

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-pin-versions: warn # off (default), warn, error

Enabled by the presets: dockerfile/hadolint.

Suppress one line with sudsy-disable-next-line apk-pin-versions 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 DL3018 full