Loading...
Loading...
Generate optimized Docker images for Bun applications. Use when deploying to containers, minimizing image sizes, setting up CI/CD pipelines, or deploying to Kubernetes.
npx skill4agent add daleseo/bun-skills bun-deploy# Verify Docker is installed
docker --version
# Verify Bun is installed locally
bun --version
# Check if project is ready for deployment
ls -la package.json bun.lockb# syntax=docker/dockerfile:1
FROM oven/bun:1-alpine AS deps
WORKDIR /app
COPY package.json bun.lockb ./
RUN bun install --frozen-lockfile --production
FROM oven/bun:1-alpine AS builder
WORKDIR /app
COPY /app/node_modules ./node_modules
COPY . .
RUN bun run build
FROM oven/bun:1-alpine AS runtime
WORKDIR /app
RUN addgroup --system --gid 1001 bunuser && \
adduser --system --uid 1001 bunuser
COPY /app/node_modules ./node_modules
COPY /app/dist ./dist
COPY /app/package.json ./
USER bunuser
EXPOSE 3000
HEALTHCHECK \
CMD bun run healthcheck.ts || exit 1
CMD ["bun", "run", "dist/index.js"]FROM oven/bun:1-alpine AS builder
WORKDIR /app
COPY package.json bun.lockb ./
RUN bun install --frozen-lockfile
COPY . .
RUN bun build ./src/index.ts --compile --outfile server
FROM gcr.io/distroless/base-debian12
COPY /app/server /server
EXPOSE 3000
ENTRYPOINT ["/server"]node_modules
bun.lockb
dist
*.log
.git
.env
.env.local
tests/
*.test.ts
coverage/
.vscode/
.DS_Store
Dockerfile
docker-compose.ymlhealthcheck.ts#!/usr/bin/env bun
const port = process.env.PORT || 3000;
const healthEndpoint = process.env.HEALTH_ENDPOINT || '/health';
try {
const response = await fetch(`http://localhost:${port}${healthEndpoint}`, {
method: 'GET',
timeout: 2000,
});
if (response.ok) {
process.exit(0);
} else {
console.error(`Health check failed: ${response.status}`);
process.exit(1);
}
} catch (error) {
console.error('Health check error:', error);
process.exit(1);
}app.get('/health', (req, res) => {
res.json({
status: 'ok',
timestamp: Date.now(),
uptime: process.uptime(),
});
});# Build image
docker build -t myapp:latest .
# Check image size
docker images myapp:latest
# Run container
docker run -p 3000:3000 myapp:latest
# Test health endpoint
curl http://localhost:3000/healthdocker-compose.ymlversion: '3.8'
services:
app:
build:
context: .
dockerfile: Dockerfile.dev
ports:
- "3000:3000"
volumes:
- .:/app
- /app/node_modules
environment:
- NODE_ENV=development
depends_on:
- db
- redis
db:
image: postgres:16-alpine
environment:
POSTGRES_USER: user
POSTGRES_PASSWORD: pass
POSTGRES_DB: mydb
ports:
- "5432:5432"
redis:
image: redis:7-alpine
ports:
- "6379:6379"docker-compose up{
"scripts": {
"docker:build": "docker build -t myapp:latest .",
"docker:run": "docker run -p 3000:3000 myapp:latest",
"docker:dev": "docker-compose up",
"docker:clean": "docker system prune -af"
}
}| Configuration | Size | Use Case |
|---|---|---|
| Bun Binary (distroless) | ~40 MB | Production (minimal) |
| Bun Alpine | ~90 MB | Production (standard) |
| Node.js Alpine | ~180 MB | Baseline comparison |
docker scan myapp:latestoven/bun# Copy dependencies first (changes less often)
COPY package.json bun.lockb ./
RUN bun install
# Copy source code last (changes more often)
COPY . .
RUN bun run build# Combine RUN commands
RUN bun install && \
bun run build && \
rm -rf tests/# Only copy what's needed in runtime
COPY /app/dist ./dist
# Don't copy: src/, tests/, .git/, node_modules (if using binary)