Docker Build & Deployment
How to build a Docker image from your Dockfile and run it.
Build Workflow
Section titled “Build Workflow”dockrion build │ ├── 1. Load and validate Dockfile ├── 2. Check secrets (or --allow-missing-secrets) ├── 3. Generate runtime files │ ├── main.py (FastAPI app from Jinja2 template) │ ├── requirements.txt (merged: your deps + Dockrion's deps) │ └── Dockerfile (multi-stage build from template) ├── 4. Resolve build context │ ├── auto_detect_imports → AST scan of entry file │ ├── build.include → explicit dirs/files/patterns │ └── build.exclude → filter out unwanted files └── 5. docker build → dockrion/{agent-name}:{tag}Running a Build
Section titled “Running a Build”Basic Build
Section titled “Basic Build”dockrion buildCreates image dockrion/my-agent:dev.
Production Build
Section titled “Production Build”dockrion build --tag v1.0.0 --no-cacheCI/CD Build (secrets not available)
Section titled “CI/CD Build (secrets not available)”dockrion build --tag $CI_COMMIT_SHA --allow-missing-secretsWith Env File
Section titled “With Env File”dockrion build --env-file .env.production --tag productionGenerated Files
Section titled “Generated Files”The build process creates .dockrion_runtime/:
.dockrion_runtime/├── main.py FastAPI application entry point├── requirements.txt Merged dependencies├── Dockerfile Docker build instructions└── (agent source files) Copied from your projectmain.py
Section titled “main.py”The generated main.py imports Dockrion packages, loads the DockSpec, creates the FastAPI app via create_app(), and configures uvicorn. It’s rendered from a Jinja2 template in the SDK.
requirements.txt
Section titled “requirements.txt”The DependencyMerger combines:
- Your project’s
requirements.txt(if present) - Dockrion’s core, runtime, and framework dependencies
- Optional dependencies (e.g.,
prometheus-client,PyJWT)
Conflicts are resolved with a precedence system: user constraints can override Dockrion’s defaults for non-core packages.
Dockerfile
Section titled “Dockerfile”The generated Dockerfile follows a standard pattern:
FROM python:3.11-slimbase image- Install system dependencies
- Copy
requirements.txtand install Python packages - Copy application source files
- Set the entrypoint to run
main.pyvia uvicorn
Image Naming
Section titled “Image Naming”dockrion/{agent-name}:{tag}| Component | Source | Default |
|---|---|---|
| Prefix | DOCKRION_IMAGE_PREFIX constant | dockrion |
| Agent name | agent.name from Dockfile | — |
| Tag | --tag flag | dev |
Example: dockrion/invoice-copilot:v1.0.0
Running the Image
Section titled “Running the Image”Basic Run
Section titled “Basic Run”docker run -d \ -p 8080:8080 \ -e OPENAI_API_KEY=sk-... \ dockrion/my-agent:devWith Environment Variables
Section titled “With Environment Variables”docker run -d \ -p 8080:8080 \ -e OPENAI_API_KEY=sk-... \ -e DOCKRION_API_KEY=my-key \ -e LOG_LEVEL=debug \ dockrion/my-agent:v1.0.0With an Env File
Section titled “With an Env File”docker run -d \ -p 8080:8080 \ --env-file .env.production \ dockrion/my-agent:v1.0.0Health Check
Section titled “Health Check”docker run -d \ -p 8080:8080 \ --health-cmd "curl -f http://localhost:8080/health || exit 1" \ --health-interval 30s \ --env-file .env \ dockrion/my-agent:v1.0.0Docker Compose
Section titled “Docker Compose”version: "3.8"services: agent: image: dockrion/my-agent:v1.0.0 ports: - "8080:8080" env_file: - .env.production healthcheck: test: ["CMD", "curl", "-f", "http://localhost:8080/health"] interval: 30s timeout: 10s retries: 3 restart: unless-stopped
redis: image: redis:7-alpine ports: - "6379:6379"Source:
deploy()inpackages/sdk-python/dockrion_sdk/;TemplateRenderer,TemplateContextinpackages/sdk-python/dockrion_sdk/templates/
Previous: 5.5 Adding Policies | Next: 5.7 Cloud Deployment →