Missing package version pins in apt-get installs

Specify package versions for apt-get install to reduce unexpected changes to build results while continuing to manage security updates.

Description

When apt-get install receives only a package name, it uses the version available in the distribution’s repository at build time. Pinning a package still leaves the build dependent on the base image and the packages the repository provides.

Potential impact

An untested update can break application compatibility. Keeping an old version pinned can leave security fixes unapplied.

Remediation

  • Specify versions using apt-get install package=version and review each package when installing several together.
  • Run apt-get update before installation in the same RUN step, and confirm that the target distribution's repository contains the selected versions.
  • Review security updates regularly, test them, and update version pins.

Version-specification examples

These snippets show the version syntax. The standard busybox image lacks apt-get, and python=2.7 is historical. For an actual build, use an apt-capable base image and a supported package version available in its repository.

Without a version specification

dockerfile
FROM busybox
RUN apt-get install python
RUN ["apt-get", "install", "python"]

With a version specification

dockerfile
FROM busybox
RUN apt-get install python=2.7

Explanation:

  • Without a version: Both the shell and JSON forms leave the version of python unspecified.
  • With a version: python=2.7 requests that specific version from the repository.

References