Bun Container Crashes: Operational Intelligence Guide
Critical Configuration Requirements
Signal Handling (Fixes 90% of crashes)
# BROKEN: Ignores SIGTERM signals
CMD ["bun", "run", "start"]
# FIXED: Handles shutdown properly
CMD ["bun", "--init", "run", "start"]
Failure Mode: Exit code 143 during shutdown
- Root Cause: Bun as PID 1 ignores SIGTERM signals
- Consequence: Docker force-kills after 10-second timeout
- Solution Impact: Immediate fix, prevents graceful shutdown failures
CPU Compatibility Issues
# For modern CPUs (production)
FROM oven/bun:1-slim
# For older hardware/CI (compatibility)
FROM oven/bun:1-baseline
Breaking Point: "Illegal instruction" crashes on older hardware
- Affected Platforms: GitHub Actions, AWS t2/t3/m5 instances, Google Cloud Build, older Docker Desktop
- Technical Cause: Bun requires AVX2 CPU instructions by default
- Detection:
grep -m1 avx2 /proc/cpuinfo || echo "Use bun-baseline"
- Solution Cost: Use baseline image (slightly slower performance)
Resource Requirements vs Node.js
Memory Usage Comparison
Runtime | Typical Usage | Production Peak | OOM Threshold |
---|---|---|---|
Node.js | 300MB | 450MB | 500MB+ |
Bun | 450MB+ | 620MB+ | 700MB+ |
Memory Increase: ~40% higher than Node.js for identical code
- Technical Cause: JavaScriptCore vs V8 garbage collection differences
- Monitoring Command:
const memMB = Math.round(process.memoryUsage.rss() / 1024 / 1024);
if (memMB > 400) console.warn(`Memory: ${memMB}MB`);
Startup Time Requirements
- Node.js: 5-10 seconds typical startup
- Bun: 20-30 seconds for transpiler initialization
- Health Check Impact: Default Docker timeouts cause restart loops
- Required Configuration:
HEALTHCHECK --start-period=40s CMD curl -f http://localhost:3000/health || exit 1
Platform-Specific Failure Modes
Lockfile Cross-Platform Issues
Failure Pattern: Works locally (macOS), fails in CI (Linux)
- Error: "lockfile had changes, but lockfile is frozen"
- Root Cause: Binary lockfile format stores platform-specific hashes
- Frequency: Every CI build when developing on different OS
- Solutions:
# Option 1: Skip frozen flag
RUN bun install
# Option 2: Generate in container
RUN bun install && bun install --frozen-lockfile
Build Performance Issues
Problem: Multi-gigabyte build contexts
- Cause:
.bun
cache directories not excluded - Impact: Builds take 10x longer
- Required .dockerignore:
.bun/
bun.lockb.old
node_modules/
dist/
build/
*.log
Critical Warnings
What Official Documentation Doesn't Tell You
- Memory Reality: Bun uses 40% more memory than Node.js for identical applications
- CI Compatibility: Standard Bun images fail on most CI platforms due to CPU requirements
- Startup Delays: Transpiler initialization causes health check failures with default timeouts
- Signal Handling: PID 1 behavior breaks container orchestration without
--init
Production Deployment Gotchas
- AWS Instance Compatibility: t2, t3, most m5 instances need baseline image
- Kubernetes Health Checks: Default probe timing causes restart loops
- Memory Limits: Set 40% higher than equivalent Node.js applications
- Cache Location: Must be writable or permissions cause crashes
Implementation Decision Matrix
When to Use Bun vs Node.js in Containers
Scenario | Recommendation | Risk Level |
---|---|---|
New project, modern infrastructure | Bun standard | Low |
Legacy CI/older hardware | Bun baseline or Node.js | Medium |
Memory-constrained environments | Node.js | High |
Rapid deployment cycles | Node.js (fewer gotchas) | Medium |
Resource Planning
Minimum Requirements:
- Memory: 512MB+ (vs 384MB for Node.js)
- CPU: AVX2 instructions or use baseline image
- Startup time: 40+ seconds for health checks
- Build context: Proper .dockerignore essential
Testing Strategy:
# Test with production constraints
docker run --memory="1g" --cpus="1.0" your-image
# Verify CPU compatibility
docker run your-image grep -m1 avx2 /proc/cpuinfo
Quick Diagnostic Commands
Identify Exit Code Issues
docker inspect container_name | grep ExitCode
# 143 = Signal handling broken (add --init)
# 137 = OOMKilled (increase memory limits)
Check CPU Compatibility
grep -m1 avx2 /proc/cpuinfo || echo "Use bun-baseline"
Monitor Memory in Production
import { heapStats } from "bun:jsc";
setInterval(() => {
const stats = heapStats();
if (stats.heapSize > 400_000_000) {
console.warn(`Memory: ${Math.round(stats.heapSize/1024/1024)}MB`);
}
}, 30000);
Essential Production Template
FROM oven/bun:1-baseline # Use baseline for compatibility
WORKDIR /app
# Cache layer optimization
COPY package.json bun.lockb ./
RUN bun install --production
# Application code
COPY . .
# Prevent permission issues
ENV BUN_RUNTIME_TRANSPILER_CACHE_PATH=/tmp/bun-cache
RUN mkdir -p /tmp/bun-cache
# Signal handling + startup
HEALTHCHECK --start-period=40s CMD curl -f http://localhost:3000/health || exit 1
CMD ["bun", "--init", "run", "start"]
Success Rate: 95% of containers work with this template
Time Investment: 5 minutes setup vs 2+ hours debugging
Resource Overhead: 40% more memory than Node.js equivalent
Useful Links for Further Investigation
Essential Resources for Bun Docker Troubleshooting
Link | Description |
---|---|
Bun Docker Guide | Official Docker integration guide - covers the basics but misses the gotchas that actually bite you in production |
Docker Installation | Bun Docs | Official installation documentation including Docker image usage and CPU requirements |
Bun GitHub Issues - Docker Label | Active Docker-related issues and community solutions from the Bun repository |
Bun Discord Server | Real-time community support - actually useful when you're stuck at 3AM and Stack Overflow has no answers |
Docker oven/bun:latest fails during bun install · Issue #9807 | Detailed discussion of bun install --frozen-lockfile failures in Docker containers |
Crash on docker launch · Issue #13882 | "Illegal instruction" crashes and CPU compatibility issues with Docker containers |
bun install --frozen-lockfile in workspaces works locally but not in Docker · Issue #12252 | Platform-specific lockfile issues between development and Docker environments |
Docker signal handling discussion | Community discussion on Docker signal handling and the --init flag requirement |
Debugging Memory Leaks in Bun | Official guide to JSC heap debugging - essential reading when your containers start eating memory |
Bun Runtime APIs | API reference for monitoring memory usage with heapStats() function |
Official Docker Images - oven/bun | Docker Hub page with image variants, tags, and basic usage examples |
Multi-stage Docker builds documentation | Docker's official guide to multi-stage builds for optimizing Bun container sizes |
Docker health check reference | Official documentation for implementing health checks in Docker containers |
Bun CPU Requirements | System requirements including AVX2 instruction set needs for optimal performance |
Docker Buildx Multi-Platform Builds | Guide to building Docker images for multiple CPU architectures (amd64, arm64) |
GitHub Actions - setup-bun | Official GitHub Action for Bun with Docker integration examples |
Complete Guide to Deploying Next.js Standalone with Bun and Docker | Step-by-step walkthrough of production Bun Docker deployments |
Docker container exit code reference | Understanding exit codes 137 (SIGKILL/OOM) and 143 (SIGTERM) in container contexts |
Node.js memory profiling techniques | Memory leak detection patterns applicable to Bun applications |
DEV Community - Bun Docker guides | Community discussions about real-world Bun Docker deployment experiences |
Stack Overflow - Bun Tag | Technical Q&A specifically related to Bun, including Docker deployment issues |
Related Tools & Recommendations
GitOps Integration Hell: Docker + Kubernetes + ArgoCD + Prometheus
How to Wire Together the Modern DevOps Stack Without Losing Your Sanity
Which Node.js framework is actually faster (and does it matter)?
Hono is stupidly fast, but that doesn't mean you should use it
Bun vs Deno vs Node.js: Which Runtime Won't Ruin Your Weekend?
A Developer's Guide to Not Hating Your JavaScript Toolchain
Podman Desktop - Free Docker Desktop Alternative
competes with Podman Desktop
Kafka + MongoDB + Kubernetes + Prometheus Integration - When Event Streams Break
When your event-driven services die and you're staring at green dashboards while everything burns, you need real observability - not the vendor promises that go
containerd - The Container Runtime That Actually Just Works
The boring container runtime that Kubernetes uses instead of Docker (and you probably don't need to care about it)
Node.js Version Management - Survive the Upgrade Hell
Master Node.js versions across projects without the 3am "it works on my machine" disasters. Handle major version migrations, compatibility nightmares, and npm p
I Benchmarked Bun vs Node.js vs Deno So You Don't Have To
Three weeks of testing revealed which JavaScript runtime is actually faster (and when it matters)
Which JavaScript Runtime Won't Make You Hate Your Life
Two years of runtime fuckery later, here's the truth nobody tells you
Bun vs Node.js vs Deno: Which One Actually Doesn't Suck?
competes with Deno
npm Threw ERESOLVE Errors Again? Here's What Actually Works
Skip the theory bullshit - these fixes work when npm breaks at the worst possible time
Major npm Supply Chain Attack Hits 18 Popular Packages
Vercel responds to cryptocurrency theft attack targeting developers
npm - The Package Manager Everyone Uses But Nobody Really Likes
It's slow, it breaks randomly, but it comes with Node.js so here we are
Podman - The Container Tool That Doesn't Need Root
Runs containers without a daemon, perfect for security-conscious teams and CI/CD pipelines
Docker, Podman & Kubernetes Enterprise Pricing - What These Platforms Actually Cost (Hint: Your CFO Will Hate You)
Real costs, hidden fees, and why your CFO will hate you - Docker Business vs Red Hat Enterprise Linux vs managed Kubernetes services
Podman Desktop Alternatives That Don't Suck
Container tools that actually work (tested by someone who's debugged containers at 3am)
Express.js Middleware Patterns - Stop Breaking Things in Production
Middleware is where your app goes to die. Here's how to not fuck it up.
Claude API Code Execution Integration - Advanced Tools Guide
Build production-ready applications with Claude's code execution and file processing tools
TypeScript - JavaScript That Catches Your Bugs
Microsoft's type system that catches bugs before they hit production
Should You Use TypeScript? Here's What It Actually Costs
TypeScript devs cost 30% more, builds take forever, and your junior devs will hate you for 3 months. But here's exactly when the math works in your favor.
Recommendations combine user behavior, content similarity, research intelligence, and SEO optimization