AnySites

// BUILD CONFIGURATION

Deploy a Next.js App

Standalone output, the generated Dockerfile, and what to check when a Next.js build fails.

Next.js projects get an auto-generated multi-stage Dockerfile when there's no Dockerfile in the repo. It installs dependencies, runs your build command (or npm run build by default), and copies the standalone build output into a slim final image.

This requires output: "standalone" in your next.config.js. Without it, there's no .next/standalone directory to copy and the build fails at that step. This is the most common Next.js-specific deploy failure on the platform.
// next.config.js
module.exports = {
  output: "standalone",
};

The generated image sets PORT to match your project's configured port and runs node server.js (the standalone entrypoint Next.js produces). If your app reads the port from process.env.PORT — which the standalone server does by default — no further configuration is needed.

If you need custom build steps (a monorepo, a non-default output directory, extra native dependencies), commit your own Dockerfile instead — see Deploy with a Custom Dockerfile — and it takes priority over auto-generation.

Related documentation