Container Deployment¶
DRACO METRIC includes a multi-stage Containerfile compatible with both Podman and Docker.
Building the Image¶
Running the Container¶
Basic¶
With custom environment variables¶
With custom worker count¶
Override the default CMD to change uvicorn options:
podman run -d \
--name draco-metric \
-p 127.0.0.1:8000:8000 \
--env-file .env \
draco-metric:latest \
--host 0.0.0.0 --port 8000 --workers 4 --limit-max-requests 10000 --timeout-keep-alive 30
Container Architecture¶
The Containerfile uses a multi-stage build:
Stage 1: Builder¶
- Base:
python:3.13-slim-bookworm - Installs
uvfor fast dependency resolution - Creates a virtual environment at
/opt/venv - Installs production dependencies only (no dev packages)
Stage 2: Production¶
- Base:
python:3.13-slim-bookworm - Copies virtual environment from builder
- Copies application code
- Runs as non-root user (
uid:gid 65532:65532)
Security Features¶
| Feature | Detail |
|---|---|
| Non-root user | nonroot user with uid/gid 65532 |
| No login shell | User shell is /usr/sbin/nologin |
| Minimal image | No build tools, compilers, or package managers |
| Production defaults | DEBUG=false, auth and security headers enabled |
| Health check | Built-in HEALTHCHECK instruction |
| Request limits | Workers restart after 10,000 requests |
Default Environment¶
These environment variables are set in the Containerfile (can be overridden at runtime):
DEBUG=false
LOG_LEVEL=WARNING
ENABLE_API_KEY_AUTH=true
ENABLE_SECURITY_HEADERS=true
RATE_LIMIT_ENABLED=true
Health Check¶
The container includes a built-in health check:
It polls http://127.0.0.1:8000/health every 30 seconds.
Check container health:
Container Management¶
View logs¶
Stop and remove¶
Restart¶
Compose Example¶
Create compose.yml:
services:
draco-metric:
build:
context: .
dockerfile: Containerfile
container_name: draco-metric
ports:
- "127.0.0.1:8000:8000"
env_file:
- .env
restart: unless-stopped
healthcheck:
test: ["CMD", "python", "-c", "import urllib.request; urllib.request.urlopen('http://127.0.0.1:8000/health', timeout=3)"]
interval: 30s
timeout: 5s
retries: 3
start_period: 10s
Run:
Image Size¶
The multi-stage build produces a minimal image. Approximate sizes:
| Component | Size |
|---|---|
| Base image (python:3.13-slim) | ~150 MB |
| Virtual environment | ~80 MB |
| Application code | < 1 MB |
| Total | ~230 MB |