apk package versions are not pinned

Leaving apk add package versions unspecified can change Docker build results.

Description

With apk add py3-pip, Alpine selects the version of py3-pip available in its repository when the image is built.

Potential impact

A deployment image rebuilt after a repository update can behave differently from the tested image, making a failure harder to reproduce or roll back.

Remediation

  • Specify each package’s version using apk add package=version.
  • Test the updated package and check it for vulnerabilities before changing the pin.

Examples

These installation excerpts assume the same supported Alpine environment. Supply a reviewed version and its -r release from that repository through PIP_APK_VERSION. Installation can fail if the pinned package disappears from the repository, so plan how required packages will remain available.

Before

dockerfile
RUN apk add --update py3-pip

After

dockerfile
ARG PIP_APK_VERSION
RUN test -n "$PIP_APK_VERSION" && apk add --update "py3-pip=${PIP_APK_VERSION}"

Explanation:

  • Before: apk selects the version of py3-pip.
  • After: The build stops if PIP_APK_VERSION is empty. Otherwise it requests that version and release of py3-pip.

References