Base bookworm image for server less and api application development
1.3K
A production-ready Docker base image for Python 3.12 uv-managed applications. Supports AWS Lambda, FastAPI/ASGI servers, and container deployments.
Quick Start:
docker pull datapsycho/uvr-base:3.12.1-bookworm
datapsycho/uvr-base is a production-ready base image for Python 3.12 uv-managed applications. It provides:
For reproducible builds, always use the immutable semantic version tag:
docker pull datapsycho/uvr-base:3.12.1-bookworm
This ensures your image build is deterministic. The 3.12.1-bookworm tag is immutable and will never change.
For development and CI where automatic updates are acceptable:
docker pull datapsycho/uvr-base:latest
The latest tag always points to the newest build and should NOT be used in production.
FROM datapsycho/uvr-base:3.12.1
WORKDIR /var/task
COPY pyproject.toml uv.lock README.md ./
COPY src/ ./src/
ENV UV_COMPILE_BYTECODE=1 \
UV_NO_DEV=1
RUN uv pip install --no-cache --system .
ENTRYPOINT ["python", "-m", "awslambdaric"]
CMD ["myapp.handler.lambda_handler"]
For multi-core web deployments on ECS Fargate or Azure App Service:
FROM datapsycho/uvr-base:3.12.1
WORKDIR /app
COPY pyproject.toml uv.lock README.md ./
COPY src/ ./src/
ENV UV_COMPILE_BYTECODE=1
RUN uv pip install --no-cache --system --group webapp .
EXPOSE 8000
# Start Gunicorn with Uvicorn workers
# Worker count is read from WORKERS env var
CMD ["gunicorn", "--config", "src/gunicorn.conf.py", "genailib.webapp:app"]
Memory & Timeout Recommendations:
| Workload | Memory | Timeout | CPU | Use Case |
|---|---|---|---|---|
| Light (CLI tools) | 512 MB | 60s | 0.18 vCPU | Simple utilities, text processing |
| Standard (APIs) | 1024 MB | 300s | 0.35 vCPU | REST endpoints, moderate I/O |
| Heavy (PDF/ML) | 2048 MB | 900s | ~0.7 vCPU | Large file processing, data transformation |
| Full Core | 3008 MB | 900s | 1.0 vCPU | High-throughput tasks, parallel processing |
| Max Performance | 10240 MB | 900s | 3.09 vCPU | CPU-intensive tasks, batch processing |
Lambda CPU Allocation (Memory ā vCPU):
š” CPU Scaling Notes:
Estimated Capacity:
Cold Start Optimization:
UV_COMPILE_BYTECODE=1 for ~2-3s faster startupThe base image sets these automatically:
| Variable | Value | Purpose |
|---|---|---|
UV_LINK_MODE | copy | Copy packages instead of symlinking (container safety) |
PYTHONOPTIMIZE | 1 | Enable Python bytecode optimization (-O flag) |
PYTHONUNBUFFERED | 1 | Real-time logging (essential for containers) |
When using Gunicorn + Uvicorn workers, configure with these environment variables:
| Variable | Default | Purpose |
|---|---|---|
WORKERS | os.cpu_count() | Number of Gunicorn worker processes (set per ECS/App Service task) |
PORT | 8000 | Server port |
TIMEOUT | 90 | Worker timeout in seconds (increase for long-running I/O tasks) |
KEEP_ALIVE | 30 | Keep-alive timeout between requests |
LOG_LEVEL | info | Logging level (debug, info, warning, error) |
RELOAD | false | Enable auto-reload on code changes (development only) |
Example ECS Fargate Task Definition:
{
"environment": [
{ "name": "WORKERS", "value": "2" },
{ "name": "TIMEOUT", "value": "120" },
{ "name": "LOG_LEVEL", "value": "info" }
]
}
uv pip install .[webapp] # Install with FastAPI, Gunicorn, Uvicorn
uv pip install .[lambda] # Install with AWS Lambda runtime and PDF tools
pip install .[webapp]
pip install .[lambda]
--no-cache with uvReduces final image size:
RUN uv pip install --no-cache --system .
Always commit uv.lock for reproducible builds:
uv pip install -r requirements.txt # Creates/updates uv.lock
git add uv.lock && git commit -m "chore: update dependencies"
Use --system flag for container deployments:
RUN uv pip install --system .
FROM datapsycho/uvr-base:3.12.1-bookworm AS builder
WORKDIR /build
COPY . .
RUN uv pip install --no-cache --system .
FROM datapsycho/uvr-base:3.12.1-bookworm
WORKDIR /app
COPY --from=builder /usr/local/lib/python3.12/site-packages /usr/local/lib/python3.12/site-packages
COPY --from=builder /build/src ./src
CMD ["python", "-m", "myapp"]
UV_COMPILE_BYTECODE=1): Minimal overheadThe base image includes system libraries for:
3.12.1-bookworm = Python 3.12, Debian 12, immutable release3.12.2-bookworm = Future patch (Python 3.12)3.13.0-bookworm = Future major (Python 3.13)Reduce build context or use .dockerignore:
.git/
.pytest_cache/
__pycache__/
*.pyc
.venv/
node_modules/
uv pip installEnsure you're using --system flag:
RUN uv pip install --system . # ā
Correct
RUN uv pip install . # ā Creates venv (breaks in containers)
Use UV_COMPILE_BYTECODE=1 in production images:
ENV UV_COMPILE_BYTECODE=1
RUN uv pip install --no-cache --system .
Content type
Image
Digest
sha256:d1cf069c7ā¦
Size
215.4 MB
Last updated
5 months ago
docker pull datapsycho/uvr-base