# Bun Dockerfile Generator

URL: /dockerizer/bun

Generate a production Dockerfile for a Bun app — cached installs, an optional build stage and a non-root runtime.

## Default configuration

- `appName` (App name): bun-app — Used for the image tag, the compose service and the OCI labels.

- `port` (Port): 3000 — The port the app listens on inside the container. Keep it above 1024 so the process can bind it without root.

- `entrypoint` (Entry file): src/index.ts — Bun runs TypeScript directly, so this can be a .ts file.

- `compile` (Bundle with `bun build`): false — Runs your `build` script and ships the bundle instead of the source tree.

- `bunVersion` (Bun version): 1

- `baseVariant` (Base image): alpine — Distroless drops the shell and the package manager for a smaller attack surface.

- `database` (Database service): none — Adds the database to docker-compose.yml with a healthcheck, a named volume and a DATABASE_URL wired into the app.

- `redis` (Redis service): false — Adds Redis to docker-compose.yml and exposes REDIS_URL to the app.

- `cacheMounts` (BuildKit cache mounts): true — Persists the package manager store between builds. Repeat builds skip the download entirely.

- `multiArch` (Multi-architecture build): false — Adds BUILDPLATFORM/TARGETARCH so `docker buildx build --platform linux/amd64,linux/arm64` cross-compiles natively.

- `healthcheck` (Healthcheck): true — Adds a HEALTHCHECK so orchestrators can restart an unresponsive container.

- `tini` (tini init): false — Runs the app under tini so signals and zombie processes are handled properly.

- `ociLabels` (OCI labels): false — Adds org.opencontainers.image.* metadata to the final image.

- `buildSecret` (Build secret mount): false — Reads a private registry token via --mount=type=secret so it never lands in an image layer.

## Generated files

### Dockerfile

Multi-stage build: dependencies, compilation and the runtime image are separate, so only what the app needs at runtime ships.

```docker
# syntax=docker/dockerfile:1
# Generated by Easypanel Dockerizer — https://easypanel.io/dockerizer

# --- Base ---------------------------------------------
FROM oven/bun:1-alpine AS base
WORKDIR /app

# --- Dependencies -------------------------------------
FROM base AS deps

# Manifests first: source changes must not bust the dependency cache
COPY package.json bun.lock* bun.lockb* ./
RUN --mount=type=cache,id=bun-store,target=/root/.bun/install/cache,sharing=locked \
    bun install --frozen-lockfile

# --- Runtime ------------------------------------------
FROM oven/bun:1-alpine AS runtime
WORKDIR /app
ENV NODE_ENV=production
ENV PORT=3000
COPY --from=deps --chown=bun:bun /app/node_modules ./node_modules
COPY --chown=bun:bun . .
USER bun
EXPOSE 3000
STOPSIGNAL SIGTERM

# Lets Docker, Compose and Easypanel see when the app is wedged
HEALTHCHECK --interval=30s --timeout=5s --start-period=10s --retries=3 \
  CMD ["bun", "-e", "fetch('http://127.0.0.1:3000/').then(r=>process.exit(r.ok?0:1)).catch(()=>process.exit(1))"]
CMD ["bun", "run", "src/index.ts"]

```

### .dockerignore

Keeps the build context small and stops secrets and local dependencies from reaching an image layer.

```bash
# Version control
.git
.gitignore
.github

# Secrets — never bake these into an image layer
.env
.env.*
!.env.example
*.pem
*.key

# Editor and OS noise
.vscode
.idea
.DS_Store
Thumbs.db

# Docs and local tooling
README.md
LICENSE
docs
.editorconfig
docker-compose*.yml
Dockerfile*
.dockerignore

# Dependencies — reinstalled inside the image from the lockfile
node_modules
**/node_modules
.pnpm-store
.yarn/cache
.yarn/unplugged
npm-debug.log*
yarn-error.log*
pnpm-debug.log*

# Test and coverage output
coverage
.nyc_output
**/*.test.ts
**/*.spec.ts

```

### docker-compose.yml

Runs the image locally with its backing services, wired together and health-gated.

```yaml
services:
  app:
    build:
      context: .
      dockerfile: Dockerfile
    restart: unless-stopped
    ports:
      - "3000:3000"
    environment:
      NODE_ENV: production

```

## Frequently asked questions

### Do I need a build step at all?

No. Bun executes TypeScript directly, so the default configuration copies your source and runs it. Turn the bundle step on only if you want a single-file output or tree shaking.

### Why is node_modules still copied if Bun is the runtime?

Bun installs into node_modules like npm does — the layout is shared, only the resolver and install speed differ.

## Related generators

- [Deno](/dockerizer/deno)

- [Node.js](/dockerizer/nodejs)

- [Hono](/dockerizer/hono)

- [Next.js](/dockerizer/nextjs)