← Back to section · Tutorials & Labs
Freezing a Reproducible PQC Lab Environment into a Docker Image
Write your PQC lab environment into a Dockerfile and pin every layer: base image, system packages and source commits all fixed, with the digest recorded after the build, so the same experiment gets the same environment on any machine.
An environment assembled on bare metal from a checklist has an inherent weakness: it lives on one machine at one point in time. One system upgrade, one change of machine, one experiment repeated three months later, and the environment may have quietly shifted — while PQC performance and behavior experiments are sensitive to exactly the things that shift: compiler versions, CPU optimization paths, OpenSSL versions. Putting the environment into a Docker image turns “the environment” from a verbal description into a file that can be verified, distributed and archived. The goal of this tutorial is not Docker syntax; it is the discipline of reproducibility: pin every layer, and leave a trace of every build.
Why a Bare-Metal Environment Is Not Enough
First, be clear about which problems the image solves. Drift: the cmake in a distribution repository today may not be the version of next month, and an apt install without version numbers produces different environments on different dates from the same command. Migration: when an experiment moves to another machine, or a colleague needs to reproduce your result, a verbally handed-over checklist always drops something, while an image moves as a whole. Rollback: when an experiment corrupts the environment, bare metal cannot return precisely to the previous state, while an image just restarts from the old digest. With these three in mind, every Dockerfile rule below has its justification — any construct that introduces nondeterminism gets rewritten as a pinned one.
Writing a Dockerfile Pinned Layer by Layer
Take an image with liboqs and oqs-provider as the example; the skeleton looks like this:
FROM ubuntu:24.04
ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update && apt-get install -y --no-install-recommends \
build-essential cmake ninja-build git pkg-config \
libssl-dev python3 python3-venv \
&& rm -rf /var/lib/apt/lists/*
ARG LIBOQS_VERSION=0.14.0
RUN git clone --depth 1 --branch ${LIBOQS_VERSION} \
https://github.com/open-quantum-safe/liboqs.git /opt/liboqs \
&& cmake -S /opt/liboqs -B /opt/liboqs/build -GNinja \
&& ninja -C /opt/liboqs/build \
&& ninja -C /opt/liboqs/build install && ldconfig
WORKDIR /lab
Each line maps to the pinning discipline: the base image never uses a bare floating latest, and for formal archiving it is pinned further to a digest (next section); system packages are at least confined to one distribution release point, and in strict setups are written with explicit package=version pins; sources are never checked out from the moving tip of a default branch, but from a release tag or a full commit hash — the example centralizes this in the LIBOQS_VERSION variable so an upgrade changes exactly one line with a readable diff. Cleaning the apt cache in the same layer and exposing build parameters as ARG both serve the same goal: the image content depends only on the Dockerfile text. Learn to recognize the anti-patterns as well: curl | sh installers, a git pull during the build, or a full distribution upgrade inside a RUN step all make the same Dockerfile produce different images on different dates; any of these means reproducibility is already broken.
Build, Digest and Verification
Tag the image with a meaningful name at build time, and record the digest:
docker build -t pqc-lab:2026-11 .
docker images --digests pqc-lab
docker run --rm pqc-lab:2026-11 openssl version
docker run --rm pqc-lab:2026-11 python3 -c "import oqs; print(oqs.oqs_version())"
A tag is a human-readable name; the digest is the fingerprint of the content. A tag can be overwritten by a newer build, while a digest corresponds one-to-one with content. When an experiment record cites its environment, it should cite the digest, not just the tag. Verification follows the same approach as the bare-metal checklist: inside the container, print the versions of the compiler, CMake, OpenSSL and liboqs one by one and tick them against the expected table; then run a minimal ML-KEM encapsulation/decapsulation smoke test to confirm the library is not merely installed but usable. Store the verification output together with the Dockerfile in the experiment repository — that combination is the environment’s birth certificate.
Distribution and Archiving
Without an image registry, files are enough:
docker save pqc-lab:2026-11 | gzip > pqc-lab-2026-11.tar.gz
sha256sum pqc-lab-2026-11.tar.gz > pqc-lab-2026-11.tar.gz.sha256
# On the receiving side:
sha256sum -c pqc-lab-2026-11.tar.gz.sha256
docker load < pqc-lab-2026-11.tar.gz
Verify the hash before loading, to rule out transfer corruption and wrong files; after loading, compare docker images --digests against the sender’s digest, and environment equality is closed-loop confirmed before the experiment begins. For archiving, keep the Dockerfile, verification output, image file and hash file in one directory named with the date and experiment number. A note on size: images with a full toolchain typically run from several hundred MB to about 1 GB, so decide the retention policy first — environments that can be rebuilt at any time from a digest plus Dockerfile do not need every intermediate image stored, but the image behind a formally published result is worth keeping as a file.
Build Context and Layer Order: Fast, Stable Rebuilds
Beyond reproducibility, the build experience depends on two details. The first is the build context: docker build packages the current directory wholesale and sends it to the daemon, so if the experiment directory mixes packet captures, old image archives and datasets, builds slow down at the transfer stage and unrelated files can slip into the image. Exclude data, archives and temporary files from the context with .dockerignore — faster and cleaner. The second is layer order: Docker caches layer by layer, and when one layer changes, every layer after it rebuilds. So write the Dockerfile in the order “least-changing first”: base image and system packages at the front, source checkout next, your own scripts and configuration last. Then day-to-day iteration that only changes scripts hits the cache for every heavy layer in front and rebuilds in seconds; only a genuine component upgrade pays for a full build. Layer order carries one more meaning: leave a comment next to the relevant layer explaining why that version was chosen, and six months later the Dockerfile still tells you the reasoning behind the upgrade decision. Reproducibility means consistent results and an understandable process — only with both does an image deserve to be called the experiment environment.
Wrapping Up
Docker is only the container; pinning is the discipline: base image pinned to a digest, system packages pinned to versions, sources pinned to commits, builds logged, references by digest, distribution checked by hash. Do these four things and a PQC experiment’s environment stops being “it works on my machine” and becomes a fact anyone can verify. For how this combines with VM snapshots and bare-metal version pinning, see the companion article on version pinning on this site.
Tags: DockerReproducibilityImagesEnvironment Freezing