# Free Bun hosting

Run Bun, a fast JavaScript runtime and toolkit, in an always-on container built from your Dockerfile. Start from the Bun template, deploy with the CLI and add Postgres and storage for $0.

## What you can run

Any Bun web app or API that listens on HTTP, including Hono, Elysia, Express and plain `Bun.serve`.

- [Hono](/free-hono-hosting)
- [Express](/free-express-hosting)

## The starter Dockerfile

This is the `bun` template, exactly as `ezhst build dockerfile template bun` prints it.

```Dockerfile
FROM oven/bun:1-alpine
WORKDIR /app
COPY package.json bun.lock* ./
RUN bun install --frozen-lockfile
COPY . .
RUN --mount=type=secret,id=appenv,target=/run/secrets/appenv sh -c 'set -a; . /run/secrets/appenv; set +a; if grep -q "\"build\"" package.json; then bun run build; fi'
ENV NODE_ENV=production PORT=3000
EXPOSE 3000
CMD ["bun", "run", "start"]
```

## Adapt it to your app

The template installs with `bun install --frozen-lockfile`, runs `bun run build` when your `package.json` has a build script, and starts with `bun run start`. Commit `bun.lock` so the install is reproducible.

- Listen on `0.0.0.0` and the `PORT` variable, which is `3000`. A server bound to localhost never receives traffic.
- Your variables are runtime env in the container. If a build command needs them, run it in a `RUN` step that mounts the `appenv` secret, as the template does. See [build-time environment variables](/guides/build-time-environment-variables).
- Never put secrets in `ARG` or `ENV`, because they end up in the image.

```index.ts
Bun.serve({
  port: Number(process.env.PORT),
  hostname: "0.0.0.0",
  fetch() {
    return new Response("Hello from Reverhost");
  },
});
```

## Deploy it

```
npx ezhst projects create my-project --link
npx ezhst apps create my-app
npx ezhst build dockerfile template bun --apply
npx ezhst env import .env
npx ezhst deploy
```

`--apply` saves the template to the app. To use an edited copy instead, save it as `Dockerfile` and run `npx ezhst build dockerfile set -f Dockerfile`. Read [how to write a Dockerfile for Reverhost](/guides/write-a-dockerfile) for the general rules.

## Limits

Each app gets 256 MB of RAM with no swap, 0.5 CPU and images up to 1 GB. A project holds 2 apps, a 128 MB Postgres database and 256 MB of S3 storage. One build runs at a time per app, with up to 10 builds a day on the free plan. See [pricing and limits](/pricing).

## Connect Postgres and S3

```
npx ezhst db create main
npx ezhst db info --json
npx ezhst storage create files
npx ezhst storage info --json
```

Use `Bun.sql`, Postgres.js or Drizzle with `process.env.DATABASE_URL`. Use Bun's built-in `S3Client` or the AWS SDK v3 with the endpoint `https://storage.reverhost.com` and path-style requests. See the [Postgres](/products/postgres) and [storage](/products/storage) product pages.

## Frequently asked questions

### Is Bun hosting on Reverhost free?

Yes. It costs $0 per month with no credit card and no trial period, within the published limits.

### Is a Dockerfile in my repository used automatically?

No. The Dockerfile is stored on the app. Save it with `ezhst build dockerfile set -f Dockerfile`, or apply a template, before you deploy.

### Does the Bun template run on Node.js?

No. It starts from `oven/bun:1-alpine`, so your app runs on the Bun runtime. Use the Node.js template if you only use Bun as a package manager.
