Dockerfile
Last Updated: July 29, 2026 | By Mihail Sebastian | AI Dictionary
A text file of instructions that builds a Docker image: the exact OS, libraries, and code an application needs, frozen so it runs identically anywhere.
What is a Dockerfile?
A Dockerfile is a text file of instructions that Docker follows to build an image: a frozen snapshot of an operating system, libraries, and code that runs identically on any machine. It turns “works on my machine” into “works everywhere.”
For machine learning, that reproducibility is the point. A training environment depends on exact versions of Python, CUDA, and libraries like PyTorch; a Dockerfile pins all of them in one reviewable file.
How a Dockerfile Works
Each instruction adds a layer to the image. FROM picks the starting point, such as an official Python or CUDA base image; COPY brings in your code; RUN installs dependencies; CMD sets what executes when a container starts.
FROM pytorch/pytorch:2.1.0-cuda11.8-cudnn8-runtime
COPY requirements.txt .
RUN pip install -r requirements.txt
CMD ["python", "train.py"]
The ENV instruction sets default environment variables inside the image. Secrets like API keys are passed as environment variables when the container starts, never baked into the image itself.
Example of a Dockerfile
A researcher trains a model that works on her workstation, but a teammate cannot reproduce the results: different CUDA version, different library versions, subtly different numbers. The team adds the Dockerfile above to the repository.
Now every training run starts from the same image, whether it executes on a laptop, a shared GPU server, or a cloud cluster. When the model is ready to deploy, a second Dockerfile packages the inference code the same way, so the serving environment matches the one the model was trained in.
Related AI terms: Environment Variable · Deploy · CUDA · Pipeline
Did you like the Dockerfile gist?
Learn about 250+ need-to-know artificial intelligence terms in the AI Dictionary.
Mihail Sebastian — Writes about AI governance, regulation, and the technology behind them. Placeholder bio — replace with a real credential line. About