apps

Framework-specific Dockerfile generators for common web app patterns

Python apps

python_app() is the foundation — a single-stage Python Dockerfile with optional uv support. All higher-level helpers (fasthtml_app) delegate to it.


source

python_app


def python_app(
    port:int=8000, cmd:NoneType=None, image:str='python:3.12-slim', workdir:str='/app', pkgs:NoneType=None,
    volumes:NoneType=None, uv:bool=True, healthcheck:NoneType=None
):

Single-stage Python app Dockerfile. uv=True (default) uses uv for fast installs.

# Defaults: uv, port 8000
df = python_app()
s = str(df)
assert 'FROM python:3.12-slim' in s
assert 'COPY --from=ghcr.io/astral-sh/uv:latest /uv /usr/local/bin/uv' in s
assert 'RUN --mount=type=cache,target=/root/.cache/uv uv sync --frozen --no-dev' in s
assert 'COPY . .' in s
assert 'EXPOSE 8000' in s
assert 'CMD ["python", "main.py"]' in s
assert 'VOLUME' not in s
print('python_app() defaults OK'); print(df)
# With pip, apt packages, volumes, healthcheck
df = python_app(port=5001, uv=False,
    pkgs=['libpq-dev', 'curl'],
    volumes=['/app/data', '/app/uploads'],
    healthcheck='/health')
s = str(df)
assert 'apt-get install -y libpq-dev curl' in s
assert 'requirements.txt' in s
assert 'mkdir -p /app/data' in s
assert 'mkdir -p /app/uploads' in s
assert 'HEALTHCHECK' in s
assert 'VOLUME' not in s
print('python_app() pip+pkgs+volumes+healthcheck OK')

FastHTML / FastAPI

fasthtml_app() is a thin wrapper around python_app() with sensible FastHTML defaults: port 5001, uv, python main.py.


source

fasthtml_app


def fasthtml_app(
    port:int=5001, cmd:NoneType=None, image:str='python:3.12-slim', pkgs:NoneType=None, volumes:NoneType=None,
    healthcheck:NoneType=None
):

FastHTML/FastAPI single-stage Dockerfile with uv

df = fasthtml_app(port=5001)
s = str(df)
assert 'EXPOSE 5001' in s
assert 'ghcr.io/astral-sh/uv:latest' in s
assert 'CMD ["python", "main.py"]' in s
print('fasthtml_app() OK'); print(df)
# With extra apt packages and mounted data volume
df = fasthtml_app(
    port=5001,
    pkgs=['ca-certificates', 'rclone'],
    volumes=['/app/data'],
    healthcheck='/health')
s = str(df)
assert 'rclone' in s
assert 'mkdir -p /app/data' in s
assert 'HEALTHCHECK' in s
print('fasthtml_app() with pkgs+volumes+healthcheck OK')

FastAPI + React (two-stage)

fastapi_react() builds a two-stage image: Node.js frontend build → Python backend. The compiled frontend assets are copied into /app/static for the Python server to serve.


source

fastapi_react


def fastapi_react(
    port:int=8000, node_version:str='20', frontend_dir:str='frontend', build_dir:str='dist',
    image:str='python:3.12-slim', pkgs:NoneType=None, uv:bool=True, healthcheck:str='/health'
):

Two-stage Dockerfile: Node.js frontend build + Python/FastAPI backend

df = fastapi_react(port=8000)
s = str(df)
assert 'FROM node:20-slim AS frontend' in s
assert 'npm ci' in s
assert 'npm run build' in s
assert 'FROM python:3.12-slim' in s
assert 'COPY --from=frontend /build/dist /app/static' in s
assert 'uvicorn' in s
print('fastapi_react() OK'); print(df)

Go

go_app() compiles a Go binary with go build and copies it into a minimal distroless/static image. Module downloads are cached with --mount=type=cache.


source

go_app


def go_app(
    port:int=8080, go_version:str='1.22', binary:str='app', runtime:str='gcr.io/distroless/static',
    cmd:NoneType=None, cgo:bool=False
):

Two-stage Go Dockerfile: go compiler + go mod cache → distroless runtime

df = go_app(port=8080)
s = str(df)
assert 'FROM golang:1.22-alpine AS builder' in s
assert 'RUN --mount=type=cache,target=/go/pkg/mod go mod download' in s
assert 'ENV CGO_ENABLED=0' in s
assert 'go build -ldflags' in s
assert 'FROM gcr.io/distroless/static' in s
assert 'COPY --from=builder /app /app' in s
assert 'CMD ["/app"]' in s
print('go_app() OK'); print(df)

Rust

rust_app() compiles a Rust binary in release mode and copies it into a minimal image. The cargo registry is cached with --mount=type=cache to avoid re-downloading crates.


source

rust_app


def rust_app(
    port:int=8080, rust_version:str='1', binary:str='app', runtime:str='gcr.io/distroless/static',
    features:NoneType=None, release:bool=True
):

Two-stage Rust Dockerfile: cargo build → distroless runtime

df = rust_app(port=8080)
s = str(df)
assert 'FROM rust:1-slim-bookworm AS builder' in s
assert 'RUN --mount=type=cache,target=/usr/local/cargo/registry cargo build --release' in s
assert 'FROM gcr.io/distroless/static' in s
assert 'COPY --from=builder /src/target/release/app /app' in s
assert 'CMD ["/app"]' in s
print('rust_app() OK'); print(df)
# With features
df = rust_app(binary='myapp', features='postgres,redis')
s = str(df)
assert '--features postgres,redis' in s
assert '/src/target/release/myapp' in s
print('rust_app() features OK')

VedicReader example

How fasthtml_app() simplifies a real production Dockerfile. Credentials stay out of the image — they’re injected at runtime via environment variables or mounted config files.

df = fasthtml_app(
    port=5001,
    image='python:3.13-slim-bookworm',
    pkgs=['ca-certificates', 'rclone', 'gettext-base', 'libsqlite3-dev'],
    volumes=['/app/data', '/app/backups'],
    healthcheck='/health')
s = str(df)
assert 'python:3.13-slim-bookworm' in s
assert 'rclone' in s
assert 'mkdir -p /app/data' in s
assert 'HEALTHCHECK' in s
print('vedicreader-style fasthtml_app() OK'); print(df)