# Next.js Deploy a Next.js app, with its pages, server rendering and API routes, as one Node server. ## Set the build and start commands Set the package scripts to `next build` and `next start --hostname 0.0.0.0 --port 3000`. Keep `next` under `dependencies`, not `devDependencies`, because the server needs it to run. Add a health route that returns `200`: `app/api/health/route.ts`, or `pages/api/health.ts` with the Pages Router. Then set the app's health path to `/api/health` in **Configuration**. Anything named `NEXT_PUBLIC_*` ends up in the browser, where anyone can read it. Keep secrets in ordinary environment variables and read them in server code. If you already build with `output: "standalone"`, keep doing so. Copy `.next/standalone`, `.next/static` and `public` into the image and start `server.js` with `HOSTNAME=0.0.0.0`, in place of the `CMD` shown below. ## Build with a Dockerfile This Dockerfile uses npm. For pnpm, Yarn or Bun, copy that tool's lockfile instead and change the install line. ```dockerfile FROM node:24.21.0-bookworm-slim@sha256:d6aa754f16b3197301076f047b5def2f02ea1dbbc2ca920407d46d7ec7f87b20 AS build WORKDIR /app COPY package.json package-lock.json ./ RUN npm ci COPY . . RUN npm run build FROM node:24.21.0-bookworm-slim@sha256:d6aa754f16b3197301076f047b5def2f02ea1dbbc2ca920407d46d7ec7f87b20 WORKDIR /app ENV NODE_ENV=production HOST=0.0.0.0 PORT=3000 COPY --from=build --chown=10001:10001 /app ./ USER 10001:10001 EXPOSE 3000 CMD ["./node_modules/.bin/next", "start", "--hostname", "0.0.0.0", "--port", "3000"] ``` ## Deploy the app Save the Dockerfile at the source root. In **Configuration**, set the port to **3000** and the health path to `/api/health`. Add a `.dockerignore` that excludes `.env*`, `.git`, `node_modules` and `.next`, then deploy: ```sh smolcloud deploy APP_ID . ``` Open the address it prints. You can also call a route from the CLI: ```sh smolcloud request APP_ID / ``` You don't have to write a Dockerfile: see [Automatic builds](source-preparation.md). To add a database or file storage, see [Databases and files](data-services.md). See also the [Next.js deployment docs](https://nextjs.org/docs/app/getting-started/deploying).