Self-host Next.js + PostgreSQL on a VPS

The SSR-plus-database pairing behind most Next.js apps, wired with a healthchecked Postgres.

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

Specification

Status
Listed
Category
Starter Kits
Services
db, web
Ports
3000
Volumes
1
Memory
about 384 MiB
arm64
image published
amd64
image published
Settings to fill in
none
License
not yet recorded

About Next.js + PostgreSQL

The SSR-plus-database pairing behind most Next.js apps, wired with a healthchecked Postgres. Runs 2 containers (db, web), with web listening on port 3000 and keeps its data in named volumes.

What it deploys

Next.js + PostgreSQL runs as 2 services in a single Compose app, listening on port 3000, with 1 named volume mount.

ServiceImageTagPortsVolumes
db postgres 16-alpine none nextjs_postgres_db_data -> /var/lib/postgresql/data
web node 22-alpine 3000 none

Before you install

  • CPU architecture. arm64 listed. Every image lists linux/arm64 in its registry manifest. That is a manifest fact, not proof the app runs on Arm.
  • Listed. It is in the catalog. Back up the data volume before changing an image tag.
  • Host ports. It publishes port 3000 directly on the host, so open them in the VPS firewall only if you want that.

Settings and environment

You do not have to fill in anything. 2 secrets are generated at deploy and stored encrypted. Values are never shown here.

ServiceVariableValue
dbPOSTGRES_DBPreset by the template
dbPOSTGRES_PASSWORDGenerated at deploy
dbPOSTGRES_USERPreset by the template
webDATABASE_URLGenerated at deploy
webNEXT_TELEMETRY_DISABLEDPreset by the template

Install Next.js + PostgreSQL on a VPS

  1. Install Levelrail on a fresh VPS

    Run this as root on a Linux server (amd64 or arm64) with ports 80 and 443 reachable. The installer prints a setup link.

    curl -fsSL https://levelrail.com/install.sh | sudo sh
  2. Sign in

    Open the setup link, choose a password, then log the CLI in. The CLI install command is curl -fsSL https://levelrail.com/install-cli.sh | sh if the machine does not have it. See Getting started.

    levelrail-cli login --device
  3. Read the template

    Shows the entry, including its full compose.yaml.

    levelrail-cli templates get nextjs-postgres-starter
  4. Deploy it

    This deploys the template compose file as an app. The app name defaults to the template id; --name sets another.

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

Without a domain the app gets an sslip.io address. You can also deploy it from the dashboard: Apps, New app, Browse templates, then Next.js + PostgreSQL.

More in Starter Kits

All Starter Kits templates