# Deploy a Next.js app that uses Bun

Reverhost builds every app from the Dockerfile stored on it, so you choose the install step. These are the lines to use for Next.js with Bun.

## What your Dockerfile runs

| Step | Dockerfile line |
| --- | --- |
| Copy the manifests | `COPY package.json bun.lock* ./` |
| Install | `RUN npm install -g bun && bun install --frozen-lockfile` |
| Build | `npm run build`, which runs `next build` |
| Start | `next start -H 0.0.0.0 -p $PORT` |

Run scripts with `bun run <script>` if you prefer. Dev dependencies are installed before the build, and `NODE_ENV=production` is set only after it.

```Dockerfile
FROM node:22-alpine
WORKDIR /app
COPY package.json bun.lock* ./
RUN npm install -g bun && bun install --frozen-lockfile
COPY . .
RUN --mount=type=secret,id=appenv,target=/run/secrets/appenv sh -c 'set -a; . /run/secrets/appenv; set +a; npm run build'
ENV NODE_ENV=production PORT=3000
EXPOSE 3000
CMD ["sh", "-c", "exec npx next start -H 0.0.0.0 -p $PORT"]
```

## Deploy

Start from the Node.js template and replace its last line with the Next.js start command. For a smaller image, set `output: "standalone"` and run `node .next/standalone/server.js` from a multi-stage build.

```
npx ezhst projects create my-project --link
npx ezhst apps create my-app
npx ezhst link --project <project-slug> --app <app-slug>
npx ezhst build dockerfile set -f Dockerfile
npx ezhst env import .env
npx ezhst deploy
```

## Things to watch with Bun

These lines install Bun on the Node.js base image, so your app still runs on Node. To run on the Bun runtime, start from `ezhst build dockerfile template bun` instead.

Commit `bun.lock or bun.lockb`, because a frozen install fails without it. To change the install step, edit the Dockerfile and upload it again with `ezhst build dockerfile set -f Dockerfile`.

## Next steps

See the [Next.js hub](/frameworks/nextjs) for every Next.js guide, or [free Next.js hosting](/free-nextjs-hosting) for what is included.

## Frequently asked questions

### How do I change the Bun install command?

Edit the install line in your Dockerfile, upload it with `ezhst build dockerfile set -f Dockerfile`, then run `ezhst redeploy`.
