# Dockerize a Hono App Running on Bun

Yes. An agent writes a multi-stage Dockerfile, a .dockerignore and a health check for a Hono server on Bun, builds and runs the image, and opens a pull request.

[Run this on Rush](https://cloud.getrush.ai/run/dockerize-app/hono/). Opens the console with this prompt ready to send, in a Project that has your repository.

## What the agent does

The agent reads the app before it writes a Dockerfile. In a repository shaped like honojs/examples, the root `package.json` declares npm workspaces for the Cloudflare examples with `npm@10.0.0` as the package manager, but the `bun/` directory is not a workspace: its own `package.json` depends on `hono` with a caret on 4.2.4 and `@types/bun` for development, and the README says to run `bun install` there and then `bun run hello.ts`. `bun/tsconfig.json` targets ESNext with `bun-types` and sets `jsxImportSource` to `hono/jsx`. The root `.gitignore` lists `bun.lockb`, so no lockfile is committed, and there is no Dockerfile, `.dockerignore` or compose file anywhere in the repository.

`bun/hello.ts` is the server: it builds a `Hono` app with one `GET /` route that answers JSON, reads `PORT` from the environment with a fallback of 3000, logs the address, and exports `{ port, fetch: app.fetch }`, which is the shape Bun's HTTP server picks up from a module's default export. `bun/jsx.tsx` is a second entry point that serves `public/favicon.ico` through `serveStatic` from `hono/bun` and renders an HTML page with Hono's JSX. The image is built for `hello.ts`, and the pull request shows the one-line change to run `jsx.tsx` instead.

The Dockerfile has two stages on the official `oven/bun` image. The first copies `package.json` and runs `bun install --production` so the layer is cached until the dependencies change; the second copies `node_modules` from it and the source files, sets `ENV PORT=3000` and `EXPOSE 3000`, switches to the non-root `bun` user the base image provides, and ends with `CMD ["bun", "run", "hello.ts"]` so Bun receives signals directly and the container stops cleanly. A `HEALTHCHECK` runs `bun -e` with a `fetch` of the root route and exits non-zero on anything but a 2xx, which gives `docker ps` and an orchestrator a real readiness signal. `.dockerignore` excludes `node_modules`, `.git` and editor files so the build context stays small and the host's install never shadows the image's.

Because no lockfile is committed, `bun install` resolves `hono` fresh at every build, and the agent says so in the pull request rather than hiding it: it proposes committing Bun's text lockfile and dropping the ignore entry as a follow-up the maintainers decide on, and shows the `--frozen-lockfile` line that would then make builds reproducible. A `compose.yaml` with one service, the port mapping and the health check is added for local runs. The agent builds the image with `docker build`, runs it with `docker run -p 3000:3000`, waits for the health check to report healthy, requests `/` with `curl` and reads the JSON back, then stops the container and pastes the build log, the image size from `docker images` and the health state in the pull request.

## Start it with one API call

`POST https://api.phoenix.so/o/{org}/sessions`

```json
{
  "agent": "codex",
  "input": "Containerize the Bun example in the bun directory of this Hono repository and open a pull request. Read the root package.json, .gitignore and README.md, and bun/package.json, bun/tsconfig.json, bun/hello.ts, bun/jsx.tsx and bun/public first. Write bun/Dockerfile as a multi-stage build on the official oven/bun image: an install stage that copies package.json and runs bun install --production, and a runtime stage that copies node_modules and the sources, sets PORT to 3000, exposes it, runs as the non-root bun user, adds a HEALTHCHECK that fetches the root route with bun -e, and starts with bun run hello.ts. Add bun/.dockerignore excluding node_modules, .git and editor files, and bun/compose.yaml with one service, the port mapping and the health check. Do not change .gitignore; instead explain in the pull request that no Bun lockfile is committed, what that means for reproducible builds, and the frozen-lockfile line to use once one is committed. Build the image, run it, wait for the health check, request / with curl, stop the container, and paste the build log tail, the image size and the health state in the pull request. Add a short Docker section to bun/README.md or create it if absent.",
  "resources": [
    {
      "url": "https://github.com/your-org/your-app"
    }
  ]
}
```

1. **Get an API key.** In the console, open Settings, then API keys, and create a key for your org. Send it in the Authorization header as a Bearer token.
2. **Send the request.** POST the body in request.json to https://api.phoenix.so/o/{org}/sessions, with your repository as the resources URL. The run starts in its own cloud sandbox.
3. **Read what came back.** Follow the run on its live stream or wait for the run.completed webhook, then read the result and its trajectory.

## What comes back

What comes back is a pull request on its own branch, scoped to the `bun/` directory. It adds `bun/Dockerfile`, `bun/.dockerignore`, `bun/compose.yaml` and a Docker section in a README beside them, and changes nothing else: the root workspace config, the other examples and `.gitignore` are untouched, which a reviewer can confirm from the file list. The description pastes the tail of the `docker build` log, the image size from `docker images`, the health state from `docker inspect`, and the JSON that `curl` read from the running container.

The run's full record at `GET /o/{org}/sessions/{id}/messages` keeps every command: the build with each layer, the run, the wait on the health check, the request and the stop. `GET /o/{org}/p/{project}/sessions/{id}/changes` returns each new file in full. No image is pushed to a registry and nothing is deployed; the container ran only inside the sandbox.

Before merging, a reviewer checks that the install stage copies only `package.json` so dependency layers cache, that the runtime stage runs as the `bun` user, that the health check targets the same port the `PORT` variable sets, and that the pull request's note on the missing lockfile matches the team's policy. Switching the image to `jsx.tsx` is the one-word `CMD` change the description points out.

## Run it on every service without a Dockerfile

A script on your server lists the organization's repositories with `GET /o/{org}/github`, checks each for a `package.json` that names `hono` and no `Dockerfile`, and sends one `POST /o/{org}/sessions` per match with this prompt and that repository in `resources`. Each run reads its own runtime: a Node app gets a `node` base image and `npm ci`, a Bun app gets `oven/bun`, and a Workers app gets a note that it deploys with `wrangler` and needs no image. Each run opens its own pull request.

Set a `webhook_url` on the API key and Rush POSTs `run.completed` when each turn ends, with `session_url` to read the pull request from, and `run.failed` for a run that ends in failure. A `request_id` per repository makes the script safe to run again.

## Why run it on Rush?

A Dockerfile for a small server is quick to write and slow to trust: the port in `ENV` has to match the one the code reads, the health check has to pass inside the container rather than from the host, and the non-root user has to be able to read the files that were copied. Each of those is checked by building and running the image, which the agent does in a sandbox that has Docker, and it pushes only once the container reports healthy.

The pull request shows the build log, the image size and the health state from that run, and the trajectory keeps every command, so a reviewer who does not want to pull the branch can still see the image was built and answered a request.

## Frequently asked questions

### Why bun run hello.ts and not a compiled bundle?

Bun runs TypeScript directly, and the example is one file with one dependency, so a build step would add a stage without removing anything from the image. For a larger app, ask for `bun build --compile` in the prompt and the agent produces a single binary in a smaller runtime stage.

### What about the missing lockfile?

The repository ignores `bun.lockb`, so `bun install` in the image resolves `hono` within its caret range at build time and two builds a week apart can differ. The agent does not change `.gitignore` on its own; the pull request explains the trade-off and shows the frozen-lockfile install to switch to once a lockfile is committed.

### Does the health check need curl in the image?

No. The check runs `bun -e` with a `fetch` of the root route, so it uses the runtime that is already in the image and the `oven/bun` base stays as it is. It exits with a failure status when the response is not 2xx, which is what Docker reads.

### Can the same Dockerfile run jsx.tsx?

Yes. Both entry points export the same `{ port, fetch }` shape and read `PORT` the same way, so changing the `CMD` to `bun run jsx.tsx` is enough; `public/favicon.ico` is already copied with the sources. The pull request names that line.

## More Hono jobs

- [Fix Errors in a Hono Deployment](https://getrush.ai/run/fix-cloudflare-worker-errors/hono/)
- [Fix N+1 KV Reads in a Hono API](https://getrush.ai/run/fix-n-plus-one-queries/hono/)
- [Turn Sentry Errors Into Fix Pull Requests for a Hono App](https://getrush.ai/run/fix-sentry-errors/hono/)

## The same job on other stacks

- [Dockerize a Ktor Server](https://getrush.ai/run/dockerize-app/ktor/)
- [Dockerize a Laravel App](https://getrush.ai/run/dockerize-app/laravel/)
- [Dockerize a NestJS App](https://getrush.ai/run/dockerize-app/nestjs/)

## Keep reading

- [How a Rush run works on your repository, from request to pull request](https://getrush.ai/cloud/)
- [Compare cloud agents, agent sandboxes and AI code review](https://getrush.ai/compare/)
- [Rush pricing: Free, Pro and Max](https://getrush.ai/pricing/)
