# Docker

`hamur build --docker` builds as usual and then writes a `Dockerfile` and a `.dockerignore` at the app root. It works with the `bun` and `node` presets, and with the host aliases of `node`; any other preset stops before the build with `--docker needs the bun or node preset`.

A file that exists is never overwritten: the build prints `Dockerfile exists; left as is` (or `.dockerignore exists; left as is`) and goes on, so you can edit the generated files and keep them.

The `Dockerfile` has two stages. The build stage starts from `oven/bun:1.4`, installs with `bun install --frozen-lockfile` (copy your `bun.lock` next to `package.json`) and runs `bun run hamur build --preset bun` or `--preset node`. The run stage starts from `oven/bun:1.4-slim` for `bun` and `node:24-slim` for `node`, copies only `.output/`, sets `PORT=3000`, exposes it and starts `.output/server/index.mjs` with the matching runtime. Packages the build traced into `.output/server/node_modules` (see [Traced externals](/deploy/platforms/traced-externals)) travel with `.output/`, so the run stage installs nothing.

The image checks itself with a `HEALTHCHECK` that requests `/` through `bun -e` or `node -e` and `fetch`, and fails on a status of 400 or more; the slim images have no `curl`. `.dockerignore` lists `node_modules`, `.output`, `.hamur`, `.git` and `.env*`, so a secret in a local `.env` never reaches the image: pass it with `docker run -e` or your platform's settings.

````sh [deploy-docker.sh]
hamur build --docker
docker build -t my-app .
docker run -p 3000:3000 -e HAMUR_KEY="$HAMUR_KEY" my-app
````
