Skip to main content

Command menu

Jump to a page or search the catalog

Trusted Solution

Docker Templates

FastAPI Production Docker Template: Gunicorn, Non-Root, Hash-Locked Deps

Multi-stage Dockerfile and Compose for FastAPI: hash-locked wheels, slim non-root runtime, gunicorn with uvicorn workers, test stage and healthcheck.

$12.00

What you get: 1 file · 38.85 KB · ZIP

See purchase options

Product description

A production Docker setup for FastAPI and other ASGI services. Dependencies are installed from a hash-locked requirements file in a builder stage, the runtime image is python:3.12-slim with only the virtualenv and your code, it runs as uid 10001 under tini, and gunicorn manages uvicorn workers with timeouts and worker recycling. A test stage runs pytest inside the image, so a failing test fails the build.

What is inside

  • Dockerfile with 3 stages: builder (pip install --require-hashes), test (pytest), runtime (non-root, HEALTHCHECK, tini).
  • compose.yaml: read-only root filesystem, tmpfs /tmp, all capabilities dropped, no-new-privileges, CPU and memory limits, log rotation, healthcheck, optional Postgres 17 profile.
  • compose.dev.yaml: uvicorn --reload on a bind mount with Swagger UI enabled.
  • gunicorn.conf.py: workers, timeouts, max_requests with jitter, /dev/shm heartbeat dir for read-only containers, trusted proxy IPs, all overridable by env vars.
  • healthcheck.py using only the standard library.
  • Example app: /healthz liveness, /readyz readiness, a validated items API, docs disabled in production, environment-based settings.
  • 4 pytest tests, requirements.in plus hash-locked requirements.txt (FastAPI 0.165, uvicorn 0.55, gunicorn 27) and dev requirements.
  • Makefile (build, test, run, dev, lock, scan), env.example, README with setup, Poetry and uv export, proxy and worker sizing notes.

How it was checked

The locked requirements were installed with --require-hashes into a fresh Python 3.12 venv, all 4 tests passed, and the app was started with the exact gunicorn command from the Dockerfile: /healthz, /readyz and the items API answered, and healthcheck.py exited 0 against the server and 1 against a closed port. docker compose config validates all Compose files. The image itself was not built in our environment.

Requirements

Docker Engine 24+ with BuildKit, Docker Compose v2.24+. uv or pip-tools to re-lock dependencies.

Licence

Use in unlimited own and client projects. You may not resell or redistribute the template itself.

What you get

1 file · 38.85 KB

  • FastAPI-Production-Docker-Template.zipZIP · 38.85 KB
LicenseCommercial use allowed
Package checkPassed

Getly opened the uploaded files and found nothing that would stop them opening. It is not a virus scan or a quality rating.

PublishedDec 2, 2026
File size38.85 KB
File formatZIP
Versionv1.0

Tags

dockerfastapipythondockerfilegunicorndocker-composedevopstemplate
N
NeonAnvil
Pro SellerGetly Trusted

Frequently asked questions

Do I get access instantly?

Yes. This is a digital product - you can download it right after checkout, straight from your library.

Can I use it for commercial projects?

Yes. Commercial use is allowed: use it in your own business and in things you sell. You may not resell or redistribute the file itself.

What's your refund policy?

You can request a refund within 30 days. If something isn't right, request it from your order and the Getly team reviews it.

What file formats and sizes will I get?

You'll download 1 file - ZIP - 38.85 KB in total.

Do I get free updates?

Yes - when the seller ships a new version, you can re-download the latest files from your library at no extra cost. Check the changelog for recent updates.

Price

$12.00