dnf package versions are not pinned

Leaving versions unspecified in dnf install can change Docker build results.

Description

When dnf install specifies only a name, rebuilding the same Dockerfile after a repository update can install a different package version or release.

Potential impact

A deployment can fail if it installs a package whose behavior or configuration differs from the version tested.

Remediation

  • For each package, specify an exact version and release available in the repository, as in dnf install httpd-<version>-<release>.
  • Test updates and check for vulnerabilities before changing the pin.

Examples

Supply a reviewed version-release available in the selected Fedora repository through HTTPD_VERSION_RELEASE. The latest base and general update remain mutable, so pinning one package does not make the whole image reproducible.

Before

dockerfile
FROM fedora:latest
RUN dnf -y update && dnf -y install httpd && dnf clean all
RUN ["dnf", "install", "httpd"]

After

dockerfile
FROM fedora:latest
ARG HTTPD_VERSION_RELEASE
RUN test -n "$HTTPD_VERSION_RELEASE" && dnf -y update && dnf -y install "httpd-${HTTPD_VERSION_RELEASE}" && dnf clean all

Explanation:

  • Before: Neither install command specifies a release of httpd.
  • After: The build stops if HTTPD_VERSION_RELEASE is empty. Otherwise it requests that version and release of httpd.

References