Menu

1 / 5

Deploy Next.js to a VPS with Docker and HTTPS

DEV Community: docker·Mihailo Popović·9 days ago
#IxBUUmA1
#devtodocker#devto#dev#next#build
Long article (2065 words) — no AI summary yet.
Reading 0:00
15s threshold

Originally published on the OpsCrew blog .

TL;DR

Add output: "standalone" to next.config.ts so the build emits a self-contained server.js that runs with plain Node.js.

Build a three-stage Docker image (dependencies, build, run) that copies .next/standalone , .next/static and public , and starts as the non-root node user.

Run it with Docker Compose behind Caddy, which gets the HTTPS certificate itself, and next to PostgreSQL, which publishes no port.

NEXT_PUBLIC_ variables are baked into the bundle at build time, so set them where the image is built, not on the server.

To deploy Next.js to a VPS, turn on output: "standalone" , build a small Docker image from the standalone output, and run it on the server with Docker Compose, next to PostgreSQL and behind Caddy, which gets and renews the HTTPS certificate on its own .…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.