Docker solves the most persistent problem in AI agent deployment: the gap between “works on my machine” and “works in production.” By packaging your agent, its Python version, and every dependency into a single image, you guarantee identical behavior across your laptop, a CI runner, and a cloud server. This page walks you through the full workflow — from writing your firstDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/NirDiamant/agents-towards-production/llms.txt
Use this file to discover all available pages before exploring further.
Dockerfile to running a dynamic, environment-variable-driven agent container.
Reproducibility
One image runs identically on any host, eliminating version-conflict surprises.
Portability
Ship the same container to AWS, GCP, Kubernetes, or a colleague’s machine.
Separation of concerns
Keep credentials out of code by injecting them as environment variables at runtime.
Prerequisites
- Docker Desktop installed and running
- A Docker Hub account (for pushing and pulling images)
- Verify Docker is running:
Core Dockerfile instructions
ADockerfile is the image’s recipe. Each instruction either creates a new layer or adds metadata:
| Instruction | Purpose |
|---|---|
FROM | Base image (OS + runtime) |
RUN | Execute shell commands during build |
COPY | Copy files from host into image |
ENV | Set default environment variables |
ARG | Build-time parameters |
WORKDIR | Set working directory inside image |
EXPOSE | Document the port your service listens on |
CMD | Default command when the container starts |
FROM, RUN, and COPY create cacheable layers. LABEL, ENV, ARG, and CMD add metadata only.Building and running your first image
Write a minimal Dockerfile
Start from the official Python 3.10 base image and install a system dependency:
examples/ex1/Dockerfile
Build the image
Run this from the repository root. The Validate the build succeeded:
-f flag points to the Dockerfile; -t sets the name and tag:Layer caching
Docker caches every layer. When you rebuild, only layers below the first changed instruction are rebuilt. Order your Dockerfile from least-changed (base image, system packages) to most-changed (application code) to maximize cache reuse.Volume mounts
Containers are ephemeral by default — any file written inside them disappears when the container stops. Mount a local directory with-v to persist data or inject code at runtime:
Dockerizing an AI agent
The following example containers a minimal OpenAI agent. The agent script contains no credentials — the API key arrives at runtime through--env.
- Agent script
- Dockerfile
examples/ex4/simple_agent.py
Dynamic agents via environment variables
Make the agent reusable by reading the question from an environment variable:Next steps
Deploy on RunPod GPU
Push your Docker image to RunPod’s serverless GPU infrastructure for scalable inference.
Run LLMs locally with Ollama
Mount open-weight models into a container for fully offline, on-premises deployments.