Docker Templates
Next.js Production Docker Template: Multi-Stage, Non-Root, Healthcheck
Dockerfile and Compose for shipping Next.js as a small non-root standalone container with tini, a real healthcheck and a read-only root filesystem.
What you get: 1 file · 18.99 KB · ZIP
See purchase optionsProduct description
A production Dockerfile and Docker Compose setup for Next.js apps that use output: 'standalone'. The final image contains only the standalone server, static assets and public files, runs as a non-root user (uid 1001) under tini, and reports its health without curl or wget. A small Next.js 16.4 example app is included so you can see it work before you copy the files into your own project.
What is inside
- Dockerfile with 5 stages: base, deps (cached npm ci), dev (hot reload), builder, runner. BuildKit cache mount for npm, build args for NEXT_PUBLIC_* values.
- compose.yaml: read-only root filesystem, tmpfs for /tmp and .next/cache, all Linux capabilities dropped, no-new-privileges, CPU and memory limits, log rotation, healthcheck, optional Postgres 17 behind a profile.
- compose.dev.yaml: hot reload in a container with named volumes for node_modules and .next.
- scripts/healthcheck.mjs (Node fetch with a 3 second timeout) and an
/api/healthroute. - .dockerignore that keeps .env files, .git and node_modules out of the build context.
- Makefile (build, run, dev, size, scan) and env.example.
- Example app: Next.js 16.4.6, React 19.3, TypeScript, with package-lock.json.
- README with setup, pnpm and Yarn variant, monorepo notes, hardening notes and troubleshooting.
How it was checked
The example app was built with next build, the runner layout was assembled from the build output exactly as the Dockerfile copies it and started with node server.js: the page, /api/health, robots.txt and a hashed static chunk all returned 200, and the healthcheck script exited 0 against the server and 1 against a closed port. docker compose config validates all Compose files. The Docker image itself was not built in our environment, so no image size is claimed; check yours with make size.
Requirements
Docker Engine 24+ with BuildKit, Docker Compose v2.24+, a Next.js 13.4+ app with standalone output and a lockfile.
Licence
Use in unlimited own and client projects. You may not resell or redistribute the template itself.
What you get
1 file · 18.99 KB
- Nextjs-Production-Docker-Template.zipZIP · 18.99 KB
Docker Templates
Next.js Production Docker Template: Multi-Stage, Non-Root, Healthcheck
Dockerfile and Compose for shipping Next.js as a small non-root standalone container with tini, a real healthcheck and a read-only root filesystem.
Getly opened the uploaded files and found nothing that would stop them opening. It is not a virus scan or a quality rating.
Tags
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 - 18.99 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



