Docker

Docker packages application code, Python dependencies, native libraries, and a startup command into an image. In MLOps, the image is the runtime envelope for training pipelines, batch scoring jobs, and model-serving processes; the model artifact still needs its own version.

Building immutable images

A Dockerfile builds immutable layers. CI should pin the base image, install dependencies deterministically, run tests, and push an image tagged by source commit. Runtime configuration, model URIs, and secrets should be injected by the orchestrator rather than baked into the image.

Artifact: Minimal Inference Image

FROM python:3.12-slim
 
WORKDIR /app
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
 
COPY app/ ./app/
USER 65532:65532
ENV MODEL_URI=registry://fraud-scorer/41
EXPOSE 8080
CMD ["uvicorn", "app.server:api", "--host", "0.0.0.0", "--port", "8080"]

The image should start without downloading code. Loading MODEL_URI at startup links it to model-versioning while allowing rollbacks to switch model versions or container revisions independently.

Environment versus model

Two things must be reproducible, and keeping them separate is the point:

  • The environment — code, Python and native libraries, CUDA runtime — is pinned in the image and tagged by commit.
  • The model — weights, thresholds — has its own version, loaded at runtime from a pinned MODEL_URI.

Baking the model into the image couples the two: every model update forces an image rebuild, the image bloats, and you can no longer roll back code and model independently. For GPU workloads the base image must also match the host’s driver and CUDA version, a common source of “works in CI, fails on the node” drift.

Failure Modes

Containers are not reproducibility magic. Mutable tags like latest, unpinned package ranges, hidden model downloads, root users, and GPU driver mismatches still create production drift. If the container is one microservice among many, it also needs health endpoints, resource limits, and structured logs so ci-cd-for-ml can promote it safely.

References