Docker
Pre-Built Images
The simplest way to containerise your agents!
Pre-built Docker images for FastAPI Agents
are available on GitHub Container Registry (GHCR):
Repository: ghcr.io/blairhudson/fastapi-agents
Available Tags:
- Framework-specific:
pydantic-ai
smolagents
llama-index
crewai
- Version-specific:
<framework>-<minor version>
e.g.pydantic-ai-0.1
To pull a specific image:
docker pull ghcr.io/blairhudson/fastapi-agents:pydantic-ai
See all available images and tags in Versions.
Currently pre-built images support only one agent per container. If you are creating containers that can serve multiple agents, it is recommended to define your own containers.
Environment Variables
The pre-built images support the following environment variables for customisation:
Variable | Example Value | Description |
---|---|---|
AGENT_MODULE |
agent.pydantic_ai |
Path to the agent module. |
AGENT_CLASS |
agent |
Class name for the agent. |
SECURITY_MODULE |
agent.pydantic_ai |
Specifies the security module for the agent. |
SECURITY_CLASS |
validate_token |
Class name for the security depdency. |
API_ENDPOINT |
pydantic-ai |
API endpoint path for the agent. |
API_PREFIX |
/agents |
Prefix for all agent-related API endpoints. |
API_MODE |
simple |
Changes how endpoints are registered. openai changes to OpenAI-compatible endpoints. |
PORT |
8080 |
Port the application runs on within the container. |
To customize these values, pass them as -e
arguments to docker run
or define them in an .env
file.
Volume Mounting
Agents are expected to be volume-mounted at /app/agent
. You can mount your agent directory as follows:
docker run -p 8000:8080 \
-v $(pwd)/agent:/app/agent \
ghcr.io/blairhudson/fastapi-agents:pydantic-ai
If a requirements.txt
file is present in the mounted directory, it will be automatically installed at container startup.
Building Custom Containers
For production deployments, it is recommended to build your container with dependencies included. Here’s an example Dockerfile
starting from one of the pre-built base images:
FROM ghcr.io/blairhudson/fastapi-agents:pydantic-ai
# Copy your agent source code
COPY ./agent /app/agent
# Install dependencies
RUN pip install --no-cache-dir -r /app/agent/requirements.txt
Build and run the custom image:
docker build -t my-custom-agent .
docker run -p 8000:8080 my-custom-agent
This approach ensures all dependencies are baked into the image, improving startup performance and reliability.