Docker Image Layer Diagram
Layers stack bottom-to-top. Each layer is immutable and cached separately. Hover a layer for details.
FROM python:3.11-slimCACHED
Python 3.11 minimal image
RUN apt-get install gcc libgomp1 curlCACHED
System libraries for scikit-learn & OpenMP
COPY requirements.txt . && pip install -r requirements.txt
Python packages (numpy, sklearn, mlflow, fastapi)
COPY src/ /app/src/
Model code, preprocessing, serving logic
ENTRYPOINT ["uvicorn", "src.serve:app"]
FastAPI serving entrypoint on port 8000
↑ Top = runtime entrypoint | Bottom = base image
Dockerfile preview
FROM python:3.11-slim
RUN apt-get install gcc libgomp1 curl
COPY requirements.txt . && pip install -r requirements.txt
COPY src/ /app/src/
ENTRYPOINT ["uvicorn", "src.serve:app"]
Key Insight
Put rarely-changing layers (base, system deps) first - they stay cached. Put frequently-changing layers (code) last. Cache busting from code changes won't re-download dependencies.
Docker for Machine Learning - Interactive Visualization
Containerizing ML models with Docker ensures reproducibility across development, staging, and production. A typical ML image layers a Python base, system libraries (gcc, libgomp for OpenMP), Python packages (numpy, scikit-learn, fastapi), and model code. Layer ordering matters: stable layers should go first so Docker cache reuse avoids re-downloading dependencies on every code change. Multi-stage builds keep compilers and build tools out of the final image, significantly reducing size. GPU workloads require the nvidia/cuda base image, which adds ~1.7GB.
- Toggle GPU mode to switch from python:3.11-slim (128MB) to nvidia/cuda base (1.84GB)
- Enable multi-stage builds to see how the final image size drops by excluding the compiler stage
- Show cache indicators to understand which layers Docker reuses across builds
- Hover any layer to see its instruction, description, and size contribution
Part of the EngineersOfAI Interactive 3D - free interactive visualizations covering every major concept in machine learning and AI engineering. Hover any element for a plain-English explanation. No code required.