Self-host FastAPI + PostgreSQL with Levelrail

A minimal Python HTTP service wired to a Postgres database, the reference pairing for a FastAPI backend.

  • Memory256 MiB
  • Archarm64
  • Services2

How to self-host FastAPI + PostgreSQL

  1. Pull the images

    2 images are pulled on your server.

    Show images
    • python:3.12-alpine
    • postgres:16-alpine
  2. Create the app

    2 services start in a single Compose app, with 1 named volume mount for your data, on port 8000.

  3. Fill in the secrets

    2 secrets are generated and stored encrypted, 2 settings are preset, you do not have to fill in anything.

  4. Open it

    Without a domain the app gets an sslip.io address; add --domain SERVICE=HOST to use your own.

FastAPI + PostgreSQL requirements

Memory
About 256 MiB
Architectures
amd64 image published, arm64 image published
Ports
8000
Domain
Optional, an sslip.io address is used without one
Settings
none to fill in
License
not yet recorded
  • Listed. It is in the catalog but not verified. Back up the data volume before changing an image tag.
  • Host ports. It publishes port 8000 on the host, so open them in the VPS firewall only if you want that.

Install Levelrail first

On a server with Levelrail running, run the command above, or open the dashboard: Apps, New app, Browse templates, then FastAPI + PostgreSQL. New to Levelrail? Install it on a fresh VPS first.

docker pull ghcr.io/glincker/levelrail:latest

Then levelrail-cli login --device. See Getting started and the FastAPI + PostgreSQL docs page.

Deploy FastAPI + PostgreSQL your way

Every format below deploys the same pinned images. Pick the one that fits how you work.

Deploy FastAPI + PostgreSQL from the CLI

levelrail-cli templates deploy fastapi-postgres-starter --name my-fastapi-postgres-starter

Deploy FastAPI + PostgreSQL with the API

Create a token in the dashboard first. This one-click route deploys it as a trial app you can keep or remove.

curl -X POST -H "Authorization: Bearer $TOKEN" \
  https://levelrail.example.com/api/v1/service-templates/fastapi-postgres-starter/deploy

FastAPI + PostgreSQL configuration

FastAPI + PostgreSQL services

ServiceImagePortsVolumes
api python:3.12-alpine 8000 none
db postgres:16-alpine none fastapi_postgres_db_data -> /var/lib/postgresql/data

FastAPI + PostgreSQL environment variables

VariableServiceValue
DATABASE_URL api Generated at deploy
POSTGRES_DB db Preset by the template
POSTGRES_PASSWORD db Generated at deploy
POSTGRES_USER db Preset by the template

Ports and volumes

Ports
8000
Volumes
1 named mount: fastapi_postgres_db_data -> /var/lib/postgresql/data

FastAPI + PostgreSQL FAQ

How much memory does FastAPI + PostgreSQL need?

The catalog lists about 256 MiB of memory for FastAPI + PostgreSQL across its 2 services.

Does FastAPI + PostgreSQL run on arm64?

For FastAPI + PostgreSQL, an arm64 image is published; amd64 is image published.

Does FastAPI + PostgreSQL need configuration before it starts?

No. The template fills in its own defaults and generates secrets at deploy time.

Which database does FastAPI + PostgreSQL bundle?

The template includes Postgres, running as its own service.

Which ports does FastAPI + PostgreSQL use?

FastAPI + PostgreSQL listens on port 8000 inside the stack.

Where does FastAPI + PostgreSQL keep its data?

In a named volume: fastapi_postgres_db_data mounted at /var/lib/postgresql/data.

Can I deploy FastAPI + PostgreSQL on Dokploy or Dokku?

The services and pinned images on this page can be run on any Docker host. The public Dokploy templates list we compared does not have an entry with the same id for FastAPI + PostgreSQL, so on Dokploy you would use a Docker Compose application with the file from this page. Dokku deploys container images with its own commands, so the pinned image python:3.12-alpine, postgres:16-alpine is what you deploy there.

levelrail-cli templates deploy fastapi-postgres-starter --name my-fastapi-postgres-starter