Safeguard
Developer Tools•

How do you pin operating system packages in a build image?

Pinning the base image is not enough if packages install at build time. Options: snapshot archives, version pins, a private mirror, or baking packages in.

Safeguard Security Team
4 min read

Pin the base image first, then decide how to freeze packages installed on top of it. Options are a dated snapshot archive, explicit version pins, a private mirror, or building a base image once and reusing it. Choose by how often you can afford to maintain it.

The gap pinning the base leaves

A base image pinned by digest does not move. But a Dockerfile step that installs packages usually asks a package index for the current version, and the index changes. Docker's build guidance says to combine updating the package index and installing in one instruction, which avoids a stale cached index, but it does not make the versions repeatable. Two builds a month apart can install different versions of the same package with the same Dockerfile.

Four approaches

ApproachHowProsCons
Snapshot archivePoint the package manager at a dated copy of the repositoryRecreates a past state without hosting anythingDepends on an outside service, snapshots are large
Explicit version pinsName exact versions in the install commandSimple, visible in the diffOld versions can vanish from the live repository
Private mirrorKeep copies you controlSurvives upstream removalYou run and secure a service
Prebuilt base imageBuild an image with packages once, pin it by digestOne place to update, fast buildsYou own a second image and its patch cycle

For Debian systems, the reproducible-builds documentation says Debian packages must be reproducible with the packages that were available in the archive when they were built, and that you can use the project's snapshot site to create a system in that state. The snapshot site describes itself as a wayback machine for the Debian archive.

Matching the approach to the team

  1. Team that rebuilds rarely: pin versions and accept that you may have to bump them when an old version disappears.
  2. Team that must rebuild old releases: use a snapshot or a mirror, and record the snapshot date in the build record.
  3. Team with many services sharing the same packages: build one base image, pin by digest, and update it on a schedule with scanning before and after.

Keep the patch path open

The danger of freezing is staleness. Whichever approach you choose, set a date to refresh it, and scan the result. A pinned package list that nobody revisits is how known flaws survive in production for years.

A simple routine:

  1. Monthly, or when an urgent advisory appears, regenerate the package set.
  2. Scan the new image and compare against the old.
  3. Run tests, then promote the new digest.
  4. Record the change in the build record.

Do not pin what you can remove

Every package in a build image is something to maintain. Docker's guidance recommends avoiding installing packages you do not need. A smaller image has fewer things to pin, scan and patch. Move compilers and build tools into a build stage and keep them out of the final image where you can.

Try it yourself

Click through it at your own pace, or open it full screen.

Look at how operating system packages inside an image are listed and checked. That list is what your pinning strategy controls.

Where Safeguard fits

Safeguard scans container images and the packages inside them, and can open fix pull requests that stay off until you turn them on, with every category on Manual. Free scan: gold.safeguard.sh/scan.

Quick check

Is pinning package versions the same as pinning the image?

No. The image pin fixes the base. Packages installed afterwards need their own control.

Do I need a snapshot archive for non-Debian systems?

Not necessarily. Other systems offer different mechanisms, so check what your distribution provides.

Sources

Last reviewed: 19 October 2026.

Never miss an update

Weekly insights on software supply chain security, delivered to your inbox.

Self-healing security runs on Safeguard.

Your first fix PR is minutes away.

No sales call required, even your agent can complete the purchase over MCP.