# Next.js Dockerfile generator

> Generate a production multi-stage Dockerfile for Next.js, plus .dockerignore and compose.

Free Next.js Dockerfile generator. Pick your package manager, Node version, standalone output, Prisma, and healthcheck, and get a small multi-stage Dockerfile with .dockerignore, docker-compose.yml, and next.config settings.

- Page: https://benchline.fabwaseem.com/t/nextjs-dockerfile-generator
- Runs: in the browser. Input stays on the device.
- Price: free, no account
- Input: Package manager, Node version, base image, standalone, Prisma, healthcheck, port, and build-time env names.
- Output: Dockerfile, .dockerignore, docker-compose.yml, a next.config snippet, and build commands. A zip of the files.
- Keywords: nextjs dockerfile, next.js docker, standalone, pnpm, docker compose
- Updated: 2026-10-16
- Built by: Waseem Anjum (https://fabwaseem.com)

## How to use it

1. **Pick a package manager and Node version.** Choose npm, pnpm, yarn, or bun, then Node 20, 22, or 24 on Alpine or Debian slim.
2. **Toggle standalone, Prisma, and the healthcheck.** Standalone is on by default. Prisma adds prisma generate. The healthcheck calls a route with node fetch, so the image does not need curl.
3. **Copy the files and run docker build.** Download the Dockerfile, ignore file, and compose file, set output standalone in next.config, then build and run.

## Use it from an AI agent

MCP tool name: `build_nextjs_dockerfile`
MCP endpoint: https://benchline.fabwaseem.com/mcp (Streamable HTTP, no key)
HTTP: POST https://benchline.fabwaseem.com/api/v1/tools/nextjs-dockerfile-generator with the input as the JSON body
This call does not fetch anything. It runs on the arguments you send.

Generate a production Dockerfile, dockerignore, compose file, and next.config snippet for a Next.js app. Defaults match a pnpm standalone image.

### Input schema

```json
{
  "type": "object",
  "properties": {
    "packageManager": {
      "default": "pnpm",
      "type": "string",
      "enum": [
        "npm",
        "pnpm",
        "yarn",
        "bun"
      ]
    },
    "node": {
      "default": "22",
      "type": "string",
      "enum": [
        "20",
        "22",
        "24"
      ]
    },
    "base": {
      "default": "slim",
      "type": "string",
      "enum": [
        "alpine",
        "slim"
      ]
    },
    "standalone": {
      "default": true,
      "type": "boolean"
    },
    "prisma": {
      "default": false,
      "type": "boolean"
    },
    "migrate": {
      "default": false,
      "type": "boolean"
    },
    "healthcheck": {
      "default": true,
      "type": "boolean"
    },
    "healthPath": {
      "default": "/api/health",
      "type": "string"
    },
    "port": {
      "default": 3000,
      "type": "integer",
      "minimum": 1,
      "maximum": 65535
    },
    "publicEnvs": {
      "default": [],
      "type": "array",
      "items": {
        "type": "string"
      }
    },
    "telemetryDisabled": {
      "default": true,
      "type": "boolean"
    },
    "cacheMounts": {
      "default": true,
      "type": "boolean"
    },
    "turbo": {
      "default": false,
      "type": "boolean"
    }
  },
  "required": [
    "packageManager",
    "node",
    "base",
    "standalone",
    "prisma",
    "migrate",
    "healthcheck",
    "healthPath",
    "port",
    "publicEnvs",
    "telemetryDisabled",
    "cacheMounts",
    "turbo"
  ],
  "additionalProperties": false
}
```

### Example tools/call

```json
{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "tools/call",
  "params": {
    "name": "build_nextjs_dockerfile",
    "arguments": {
      "packageManager": "pnpm",
      "node": "22",
      "base": "slim",
      "standalone": true,
      "prisma": false,
      "migrate": false,
      "healthcheck": true,
      "healthPath": "/api/health",
      "port": 3000,
      "publicEnvs": [],
      "telemetryDisabled": true,
      "cacheMounts": true,
      "turbo": false
    }
  }
}
```

Setup for Claude, Cursor, and VS Code: https://benchline.fabwaseem.com/mcp/guide

## Questions

### What does output: standalone do?

Next.js traces the files the server needs and writes a minimal server.js plus those files to .next/standalone. The runtime image does not need a full node_modules install. You still copy public and .next/static yourself.

### Why multi-stage?

The dependency and build stages can hold the compiler and the package cache. Docker ships only the last stage, so the production image stays smaller.

### Should I use alpine or slim?

Slim is the safer default. It uses glibc, which matches sharp and most Prisma engines. Alpine is smaller and uses musl. On Alpine, set Prisma binaryTargets to a linux-musl target or the query engine will be missing.

### How do NEXT_PUBLIC_ env vars work in Docker?

Next.js inlines NEXT_PUBLIC_ values at build time, so pass them as build args. Server-only secrets are read at runtime. Do not put those secrets in ARG.

### Why run as non-root?

A non-root user limits the damage if the app is compromised. The image creates a nextjs user and gives that user ownership of the app files so the runtime cache can be written.

### Does it work with Coolify, Railway, or Fly?

Yes. Any Docker host can run the image. Expose port 3000, pass runtime env on the platform, and pass NEXT_PUBLIC_ values at build time.

## Related tools

- [Cron expression builder](https://benchline.fabwaseem.com/t/cron-expression-builder): Build or paste a cron schedule, read it in plain English, and see the next run times.
- [OG image generator](https://benchline.fabwaseem.com/t/og-image-generator): Pick a template, watch the card update, then download the PNG or copy the Next.js file.
- [JSON-LD schema generator](https://benchline.fabwaseem.com/t/schema-generator): Fill a form, get valid schema.org JSON-LD for Article, FAQ, Product, Organization, and more.
- [JWT decoder](https://benchline.fabwaseem.com/t/jwt-decoder): Paste a JSON Web Token, read the claims, and verify the signature in the browser.
