Skip to content
Bun Docker logo

Bun Docker

Use for Docker with Bun, Dockerfiles, oven/bun image, containerization, and deployments.

SKILL.md

Full skill instructions

Bun Docker

Deploy Bun applications in Docker containers using official images.

Official Images

# Latest stable
docker pull oven/​bun

# Specific version
docker pull oven/​bun:1.0.0

# Variants
oven/​bun:latest       # Full image (~100MB)
oven/​bun:slim         # Minimal image (~80MB)
oven/​bun:alpine       # Alpine-based (~50MB)
oven/​bun:distroless   # Distroless (~60MB)
oven/​bun:debian       # Debian-based (~100MB)

Basic Dockerfile

FROM oven/​bun:1 AS base

WORKDIR /​app

# Install dependencies
COPY package.json bun.lockb ./
RUN bun install --frozen-lockfile

# Copy source
COPY . .

# Run
EXPOSE 3000
CMD ["bun", "run", "src/​index.ts"]

Multi-Stage Build (Production)

# Build stage
FROM oven/​bun:1 AS builder

WORKDIR /​app

COPY package.json bun.lockb ./
RUN bun install --frozen-lockfile

COPY . .
RUN bun run build

# Production stage
FROM oven/​bun:1-slim AS production

WORKDIR /​app

# Copy only production dependencies
COPY package.json bun.lockb ./
RUN bun install --frozen-lockfile --production

# Copy built assets
COPY --from=builder /​app/​dist ./​dist

# Run as non-root
USER bun

EXPOSE 3000
CMD ["bun", "run", "dist/​index.js"]

Alpine Image

FROM oven/​bun:1-alpine

WORKDIR /​app

# Alpine uses apk for packages
RUN apk add --no-cache git

COPY package.json bun.lockb ./
RUN bun install --frozen-lockfile

COPY . .

CMD ["bun", "run", "src/​index.ts"]

Distroless Image

# Build stage
FROM oven/​bun:1 AS builder

WORKDIR /​app
COPY . .
RUN bun install --frozen-lockfile
RUN bun build src/​index.ts --compile --outfile=app

# Runtime stage
FROM gcr.io/​distroless/​base

COPY --from=builder /​app/​app /​app

ENTRYPOINT ["/​app"]

Docker Compose

# docker-compose.yml
version: "3.8"

services:
  app:
    build: .
    ports:
      - "3000:3000"
    environment:
      - NODE_ENV=production
      - DATABASE_URL=postgres://db:5432/​app
    depends_on:
      - db
    restart: unless-stopped

  db:
    image: postgres:16-alpine
    environment:
      POSTGRES_DB: app
      POSTGRES_USER: user
      POSTGRES_PASSWORD: password
    volumes:
      - postgres_data:/​var/​lib/​postgresql/​data

volumes:
  postgres_data:

Hot Reload in Development

# docker-compose.dev.yml
version: "3.8"

services:
  app:
    build:
      context: .
      dockerfile: Dockerfile.dev
    ports:
      - "3000:3000"
    volumes:
      - ./​src:/​app/​src
      - ./​package.json:/​app/​package.json
    command: bun --hot run src/​index.ts
# Dockerfile.dev
FROM oven/​bun:1

WORKDIR /​app

COPY package.json bun.lockb ./
RUN bun install

# Source mounted as volume
CMD ["bun", "--hot", "run", "src/​index.ts"]

Compiled Binary

FROM oven/​bun:1 AS builder

WORKDIR /​app
COPY . .
RUN bun install --frozen-lockfile
RUN bun build src/​index.ts --compile --outfile=server

# Minimal runtime
FROM ubuntu:22.04

# Install runtime dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
    ca-certificates \
    && rm -rf /​var/​lib/​apt/​lists/​*

COPY --from=builder /​app/​server /​usr/​local/​bin/​server

USER nobody
EXPOSE 3000
CMD ["server"]

SQLite with Docker

FROM oven/​bun:1

WORKDIR /​app

COPY package.json bun.lockb ./
RUN bun install --frozen-lockfile

COPY . .

# Create data directory
RUN mkdir -p /​app/​data

# Volume for SQLite database
VOLUME /​app/​data

ENV DATABASE_PATH=/​app/​data/​app.sqlite

CMD ["bun", "run", "src/​index.ts"]

Health Checks

FROM oven/​bun:1

WORKDIR /​app
COPY . .
RUN bun install --frozen-lockfile

EXPOSE 3000

HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
  CMD curl -f http://localhost:3000/​health || exit 1

CMD ["bun", "run", "src/​index.ts"]
// Health endpoint
app.get("/​health", (c) => c.json({ status: "ok" }));

Environment Variables

FROM oven/​bun:1

WORKDIR /​app

# Build-time args
ARG NODE_ENV=production
ARG API_URL

# Runtime env
ENV NODE_ENV=${NODE_ENV}
ENV API_URL=${API_URL}

COPY . .
RUN bun install --frozen-lockfile

CMD ["bun", "run", "src/​index.ts"]
# Build with args
docker build --build-arg API_URL=https://api.example.com -t myapp .

# Run with env
docker run -e DATABASE_URL=postgres://... myapp

Caching Optimization

FROM oven/​bun:1 AS base

WORKDIR /​app

# Cache dependencies separately
FROM base AS deps
COPY package.json bun.lockb ./
RUN bun install --frozen-lockfile

# Build
FROM deps AS builder
COPY . .
RUN bun run build

# Production
FROM base AS runner
COPY --from=deps /​app/​node_modules ./​node_modules
COPY --from=builder /​app/​dist ./​dist
COPY package.json ./

USER bun
CMD ["bun", "run", "dist/​index.js"]

Security Best Practices

FROM oven/​bun:1-slim

WORKDIR /​app

# Don't run as root
USER bun

# Copy with correct ownership
COPY --chown=bun:bun package.json bun.lockb ./
RUN bun install --frozen-lockfile --production

COPY --chown=bun:bun . .

# Read-only filesystem
# (use with: docker run --read-only)

EXPOSE 3000
CMD ["bun", "run", "src/​index.ts"]

.dockerignore

node_modules
.git
.gitignore
*.md
Dockerfile*
docker-compose*
.env*
.DS_Store
coverage
dist
.bun

Common Commands

# Build
docker build -t myapp .

# Run
docker run -p 3000:3000 myapp

# Run with env file
docker run --env-file .env -p 3000:3000 myapp

# Interactive shell
docker run -it oven/​bun sh

# Check Bun version
docker run oven/​bun bun --version

Common Errors

ErrorCauseFix
bun.lockb not foundMissing lockfileRun bun install locally
EACCES permissionFile ownershipUse --chown=bun:bun
OOM killedMemory limitIncrease container memory
No space leftLarge layersUse multi-stage builds

When to Load References

Load references/​optimization.md when:

  • Image size reduction
  • Layer caching
  • Build performance

Load references/​kubernetes.md when:

  • K8s deployment
  • Horizontal scaling
  • Service mesh

More skills from majiayu000

xiaohongshu logo
majiayu000/claude-arsenal

xiaohongshu

xiaohongshu

286 148
View
agent-task-conductor logo
majiayu000/claude-skill-registry

agent-task-conductor

Conduct multi-agent task orchestration and workflow coordination.

663 1
View
conductor-setup logo
majiayu000/claude-skill-registry

conductor-setup

Initialize project with Conductor artifacts (product definition,

663 1
View
animation-designer logo
majiayu000/claude-skill-registry

animation-designer

Expert in web animations, transitions, and motion design using Framer Motion and CSS

663 1
View
diagramming logo
majiayu000/claude-skill-registry

diagramming

Creates Mermaid and ASCII diagrams for flowcharts, architecture, ERDs, state machines, mindmaps, and more. Use when user mentions diagram, flowchart, mermaid, ASCII diagram, text diagram, terminal diagram, visualize, C4, mindmap, architecture diagram, sequence diagram, ERD, or needs visual docume...

663 1
View
h3-pg logo
majiayu000/claude-skill-registry-data

h3-pg

PostgreSQL bindings for H3 hexagonal grid system. Use when working with H3 cells in Postgres, including spatial indexing, geometry/geography integration, and raster analysis.

23 1
View
conductor-development logo
majiayu000/claude-skill-registry

conductor-development

Context-Driven Development skill for projects using Conductor. Use this skill when you detect a `conductor/` directory in the project, when working on tasks defined in a `plan.md` file, or when the user asks about tracks, specs, or plans. Automatically applies TDD workflow, tracks task completion...

663 1
View
conductor-status logo
majiayu000/claude-skill-registry

conductor-status

Display project status, active tracks, and next actions

663 1
View
dockerization logo
majiayu000/claude-skill-registry

dockerization

Official Stakpak application containerization standard operating procedure, a step-by-step guidline to properly dockerize applications. This is a rule book curated by the Stakpak Team.

663 1
View

Popular AI tools

Kaiber logo
Video

Kaiber

Generate, edit, and beat-sync AI video with leading models in one workspace.

Paid
View
Vimcal logo
Productivity

Vimcal

The world's fastest calendar for remote work

Free
View

Transform Your Design with AI Designer by ImgCreator.ai

Freemium
View
Akool AI logo
Content & writing

Akool AI

Revolutionizing Video Production with AI-Powered Creativity

Paid
View

Extend an image past the frame and let AI fill the new aspect ratio.

Freemium
View
StarByFace logo
Security

StarByFace

Discover your celebrity doppelgänger with StarByFace!

Free
View
C

ChainClarity explains 700+ crypto whitepapers in plain English, with layered summaries, comparisons, research tools, alerts, and a $4.99 Pro plan.

Freemium
View
Opus Clip logo
Coding & apps

Opus Clip

Opus.ai: Revolutionize Your Web Experience

Free
View