Exit 143 Crashes During Container Shutdown

Docker Signal Handling

Your container dies during shutdown because Bun's acting like a deaf kid when Docker tries to shut it down. When Bun runs as PID 1, it completely ignores the SIGTERM signals Docker's sending. Docker waits around for 10 seconds like a patient parent, then says 'fuck it' and kills everything with SIGKILL - hello exit code 143.

## Breaks during shutdown
CMD [\"bun\", \"run\", \"start\"]

## Actually handles signals
CMD [\"bun\", \"--init\", \"run\", \"start\"]

Add `--init` to your CMD and the crashes stop. This spawns tini - a tiny init process that actually handles shutdown signals and forwards them to Bun. Without it, Docker gives up after 10 seconds and kills your container. Classic PID 1 fuckery that bites every containerized app.

CPU Instruction Crashes on Older Hardware

AVX2 Instruction Error

Bun crashes with "Illegal instruction" on older hardware because it needs AVX2 CPU instructions. This hits GitHub Actions, older AWS instances (anything t2/t3, most m5 instances), Google Cloud Build, and basically any CI runner using budget CPUs. It also fucks over Docker Desktop on older Macs.

oh no: Bun has crashed. This indicates a bug in Bun, not your code.
Illegal instruction at address 0x2B11410

## This cryptic bullshit error means your CPU is too old for Bun's optimized build.
## Took forever to figure out this was AVX2 bullshit.
## Stack Overflow was useless. Found the answer buried in some GitHub issue.
## GitHub Actions is basically guaranteed to not have modern CPU instructions.

Use the baseline binary for older hardware. The baseline build targets x86-64-v1 without modern extensions:

FROM oven/bun:1-baseline

This solves compatibility with older VPS providers, legacy cloud instances, and shared hosting that don't support advanced vector extensions.

Lockfile Platform Issues Break CI

Multi-platform Docker Build

Lockfile problems happen when you develop on macOS but deploy to Linux containers. Bun's binary lockfile format stores platform-specific data that breaks CI builds when platforms don't match.

error: lockfile had changes, but lockfile is frozen

## This happens every damn time you go from Mac dev to Linux container.
## Works fine locally, breaks instantly on every single CI run.
## Took forever to figure out it was binary lockfile platform differences.

Skip the frozen flag or generate the lockfile in Docker:

## Just install normally
RUN bun install

## Or generate lockfile in container first
RUN bun install && bun install --frozen-lockfile

Memory Issues and OOMKilled Containers

Docker Exit Code 137 Memory

Bun's hungrier for memory than Node because it uses JavaScriptCore instead of V8. Same code that sips 300MB in Node suddenly wants 450MB+ in Bun. JavaScriptCore is hungry as hell.

## Exit code 137 = SIGKILL from OOM
## Had our production API running fine locally - using maybe 300MB.
## Deployed to production and everything started OOMing at 700MB.
## Spent hours thinking it was a memory leak before I realized
## Bun just uses way more RAM than Node. Same exact code, 40% more memory usage.

Set explicit memory limits and clear cache location:

ENV BUN_RUNTIME_TRANSPILER_CACHE_PATH=/tmp/bun-cache
RUN mkdir -p /tmp/bun-cache

Build Context Size Problems

Docker builds are slow because standard .dockerignore files don't exclude Bun's cache directories. The .bun folder grows to gigabytes and slows your builds.

.bun/
bun.lockb.old
node_modules/
dist/
build/
*.log

Health Check Failures and Restart Loops

Health checks fail because Bun takes longer to start than Node.js. Bun.serve() needs time to warm up the transpiler and initialize, but Docker expects the server to be ready immediately.

## Give Bun time to start
HEALTHCHECK --start-period=40s \
  CMD curl -f http\://localhost\:3000/health || exit 1

90% of crashes are missing the --init flag. Add that first - 5 minutes if you're lucky, 2 hours if Docker decides to be a pain in the ass. Then worry about memory limits and health check timing. Everything else is just optimization bullshit that doesn't matter until you fix the basics.

Quick Diagnosis - Figure Out What's Broken

Container Orchestration Troubleshooting

Exit Code 143: Containers Die During Shutdown

docker inspect container_name | grep ExitCode
## \"ExitCode\": 143 = signal handling broken

Add --init to your CMD and the crashes stop. This fixes 90% of exit 143 issues. The --init flag spawns tini to handle signal forwarding and zombie reaping. Without it, Bun doesn't respond to SIGTERM and Docker force-kills containers after the shutdown timeout.

CMD [\"bun\", \"--init\", \"run\", \"start\"]

\"Illegal Instruction\" on Old Hardware

Bun CPU Compatibility

Check if your platform supports AVX2 instructions:

grep -m1 avx2 /proc/cpuinfo || echo \"Use bun-baseline\"

Switch to the baseline image for older CPUs:

FROM oven/bun:1-baseline

Lockfile Fails in CI But Works Locally

Your Mac generates different lockfiles than Linux containers because of the binary lockfile format storing platform-specific hashes. This breaks CI every damn time - works fine locally, fails on every single CI build. The binary lockfile format stores platform-specific hashes that CI runners can't handle. Skip `--frozen-lockfile` or generate the lockfile in Docker:

## Generate lockfile in container first
RUN bun install && bun install --frozen-lockfile

Memory Issues and OOMKilled

JavaScriptCore vs V8

Bun uses more memory than Node because JavaScriptCore is hungrier than V8. JSC's garbage collector holds onto memory longer and uses more of it. This leads to containers getting OOMKilled and exit code 137. Set cache path and increase limits:

ENV BUN_RUNTIME_TRANSPILER_CACHE_PATH=/tmp/bun-cache
RUN mkdir -p /tmp/bun-cache

Health Checks Fail

Bun takes its sweet time starting up compared to Node. Server initialization includes transpiler setup, module loading, and JSC warmup. Docker health checks fail during this startup period, causing restart loops. Increase the health check start period:

HEALTHCHECK --start-period=40s CMD curl -f http\://localhost\:3000/health || exit 1

Most crashes are missing the --init flag. Fix that first, then check memory limits and health check timing.

Common Bun Docker Container Failures - Quick Fixes

Q

Why does my Bun container die with exit code 143?

A

Docker's sending SIGTERM signals but Bun's ignoring them. When Bun runs as PID 1 without init handling, it acts like a deaf process that ignores shutdown requests.

Quick Fix:

## Change this
CMD ["bun", "run", "start"]

## To this
CMD ["bun", "--init", "run", "start"]

The --init flag spawns a tiny init process that properly forwards signals to Bun. Without it, Docker force-kills containers after the shutdown timeout.

Q

"Illegal instruction (core dumped)" - what does this mean?

A

Your CPU is too old for Bun's optimized build. This happens constantly on GitHub Actions, older AWS instances, or any CI runner using budget hardware.

Quick Fix:

## Use baseline binaries for older hardware
RUN curl -fsSL https://bun.sh/install | bash -s "bun-baseline"

Or check your cloud instance type - newer instance families (like AWS m6i vs m5) have better CPU instruction support.

Q

bun install --frozen-lockfile works locally but fails in Docker - why?

A

Your Mac generates different lockfiles than Linux containers because of the binary lockfile format storing platform-specific hashes. This breaks CI every damn time - works great on my machine, fails on every single CI build.

Quick Fix:

## Try installation with fallback
RUN bun install --frozen-lockfile || \
    (rm -f bun.lockb && bun install)

For production builds, generate your lockfile on the same platform as your deployment target.

Q

My Bun container gets OOMKilled even with plenty of memory - what's wrong?

A

Bun uses JavaScriptCore instead of V8, which is hungrier for memory. Same code that used 300MB in Node.js suddenly wants 450MB in Bun.

Quick Fix:

## Set explicit memory management
ENV BUN_RUNTIME_TRANSPILER_CACHE_PATH=/tmp/bun-cache
CMD ["bun", "--init", "--max-old-space-size=512", "run", "start"]

Also monitor actual memory usage with Bun's built-in tools:

// Bun-specific memory debugging (not available in Node)
import { heapStats } from "bun:jsc";
setInterval(() => {
  const stats = heapStats();
  if (stats.heapSize > 400_000_000) {
    console.warn(`Memory getting chunky: ${Math.round(stats.heapSize/1024/1024)}MB`);
  }
}, 30000);
Q

Docker build takes forever when copying files - how to fix?

A

Your .dockerignore is missing Bun's cache garbage. The .bun folder grows to several gigabytes and makes your builds crawl.

Quick Fix:

node_modules/
.bun/
.next/
dist/
build/
.cache/
*.log

This reduces build context from gigabytes to megabytes for typical Bun projects.

Q

Health checks fail but the container seems to be running - what's happening?

A

Bun takes its sweet time starting up. The HTTP server isn't ready when Docker starts health checks, so your container gets marked unhealthy and restarts.

Quick Fix:

## Give Bun more time to start up
HEALTHCHECK --interval=30s --timeout=5s --start-period=30s --retries=3 \
  CMD curl -f http\://localhost\:3000/health || exit 1

The start-period of 30s accounts for Bun's initialization time.

Q

bun run doesn't exit in Docker - process keeps running

A

This usually happens with database connections or event listeners that prevent graceful shutdown.

Quick Fix:

// Add proper signal handling
process.on('SIGTERM', () => {
  console.log('Shutting down gracefully');
  // Close database connections, servers, etc.
  process.exit(0);
});
Q

Docker container restarts in a loop with "Error: spawn EACCES"

A

File permissions are wrong, usually because you're running as root when you shouldn't be, or vice versa.

Quick Fix:

## Create and use non-root user
RUN addgroup --system --gid 1001 bunjs && \
    adduser --system --uid 1001 bunjs

## Fix permissions
COPY --chown=bunjs:bunjs . .
USER bunjs
Q

Bun install fails with "unable to resolve" errors in Docker

A

DNS is fucked inside the container. This happens with corporate firewalls or proxy settings that work fine for browsers but break containers.

Quick Fix:

## Test network connectivity during build
RUN ping -c 1 registry.npmjs.org || echo "Network issues detected"

## Use alternative registry if needed
RUN bun install --registry https://registry.npmjs.org/
Q

Container works in development but crashes in production

A

Something's different between dev and prod. Usually it's memory limits, CPU differences, or missing environment variables that nobody documented.

Quick Fix:

## Test with production-like constraints
docker run --memory="1g" --cpus="1.0" your-image

## Check environment variables
docker run --rm your-image env | grep -E "(NODE_|BUN_|PATH)"

Test your container with the same resource limits as production before deploying.

Stop Containers From Crashing

JavaScript Runtime Performance Comparison

Use the Right Base Image

## For new CPUs
FROM oven/bun:1-slim

## For older hardware or CI
FROM oven/bun:1-baseline

Use `bun:1-baseline` for older hardware and CI. Most cloud instances and GitHub Actions need the baseline image because they don't have AVX2 instructions. This includes standard AWS instances, Google Cloud VMs, Azure containers, and most CI environments that use older CPU architectures for compatibility.

Essential Dockerfile Template

FROM oven/bun:1-slim
WORKDIR /app

## Copy and install first (caching)
COPY package.json bun.lockb ./
RUN bun install --production

## Copy source
COPY . .

## Set cache path
ENV BUN_RUNTIME_TRANSPILER_CACHE_PATH=/tmp/bun-cache
RUN mkdir -p /tmp/bun-cache

## Use init flag for signal handling
CMD ["bun", "--init", "run", "start"]

The `--init` flag prevents most crashes. The cache path stops permission errors. Everything else is just optimization.

Monitor Memory Early

Add simple memory logging before things break:

// Add to your main file
setInterval(() => {
  const memMB = Math.round(process.memoryUsage.rss() / 1024 / 1024);
  if (memMB > 400) console.warn(`Memory: ${memMB}MB`);
}, 30000);

// Real example: our API started at 180MB, climbed to 620MB after 6 hours.
// OOMKilled at 700MB limit. Same Node.js code peaked around 450MB.

Bun's hungrier for memory than Node - about 40% more in my experience. Monitor memory usage before containers get OOMKilled. JavaScriptCore just handles memory differently than V8, and not in a good way for containers.

Proper .dockerignore

node_modules/
.bun/
dist/
build/
.cache/
*.log
.DS_Store

Exclude Bun's cache directories or builds take forever. The `.bun` folder grows to gigabytes and kills your build performance.

Health Check Timing

Docker Health Check Configuration

## Bun needs more startup time
HEALTHCHECK --start-period=40s \
  CMD curl -f http\://localhost\:3000/health || exit 1

Bun takes longer to start than Node - sometimes 20-30 seconds vs Node's 5-10 seconds. Give it more time or health checks fail and containers restart in loops. Learned this the hard way when our Kubernetes pods kept crashing on startup and the logs just said 'unhealthy' - which tells you exactly nothing.

Test With Production Constraints

## Test memory limits
docker run --memory=\"1g\" your-image

## Test CPU constraints
docker run --cpus=\"1.0\" your-image

Test with the same memory and CPU limits you'll use in production. Test with production constraints or you'll find out the hard way during deployment.

Most crashes happen because of missing `--init` or memory limits. Fix those first, then optimize. Everything else is just paperwork that makes you feel productive but doesn't solve the real problems.

Essential Resources for Bun Docker Troubleshooting

Related Tools & Recommendations

integration
Similar content

Jenkins Docker Kubernetes CI/CD: Deploy Without Breaking Production

The Real Guide to CI/CD That Actually Works

Jenkins
/integration/jenkins-docker-kubernetes/enterprise-ci-cd-pipeline
100%
troubleshoot
Similar content

Fix Docker Swarm Service Discovery & Routing Mesh Failures

When your containers can't find each other and everything goes to shit

Docker Swarm
/troubleshoot/docker-swarm-production-failures/service-discovery-routing-mesh-failures
98%
compare
Similar content

Bun vs Node.js vs Deno: Production & Enterprise Deployment 2025

Which JavaScript Runtime Won't Get You Fired When Production Falls Apart?

Bun
/compare/bun/node-js/deno/production-enterprise-deployment
88%
troubleshoot
Similar content

Fix Docker Permission Denied on Mac M1: Troubleshooting Guide

Because your shiny new Apple Silicon Mac hates containers

Docker Desktop
/troubleshoot/docker-permission-denied-mac-m1/permission-denied-troubleshooting
72%
troubleshoot
Similar content

Fix Docker Container Startup Failures: Troubleshooting & Debugging Guide

Real solutions for when Docker decides to ruin your day (again)

Docker
/troubleshoot/docker-container-wont-start-error/container-startup-failures
67%
troubleshoot
Similar content

Docker Desktop Security Hardening: Fix Configuration Issues

The security configs that actually work instead of the broken garbage Docker ships

Docker Desktop
/troubleshoot/docker-desktop-security-hardening/security-configuration-issues
66%
troubleshoot
Similar content

Fix Docker Build Context Too Large: Optimize & Reduce Size

Learn practical solutions to fix 'Docker Build Context Too Large' errors. Optimize your Docker builds, reduce context size from GBs to MBs, and speed up develop

Docker Engine
/troubleshoot/docker-build-context-too-large/context-optimization-solutions
64%
howto
Similar content

Bun Production Deployment Guide: Docker, Serverless & Performance

Master Bun production deployment with this comprehensive guide. Learn Docker & Serverless strategies, optimize performance, and troubleshoot common issues for s

Bun
/howto/setup-bun-development-environment/production-deployment-guide
63%
troubleshoot
Similar content

Bun Memory Leaks in Production: Debugging & Fixes Guide

🏃‍♂️ Bun JavaScript Runtime Memory Troubleshooting Guide

Bun
/troubleshoot/bun-production-memory-leaks/production-memory-leaks
63%
tool
Similar content

Docker Daemon (dockerd): What it is, How it Works & Fixes

What Docker daemon actually is and why it'll drive you nuts at 3am

Docker Daemon (dockerd)
/tool/docker-daemon/overview
63%
tool
Recommended

Podman Desktop - Free Docker Desktop Alternative

competes with Podman Desktop

Podman Desktop
/tool/podman-desktop/overview
62%
troubleshoot
Similar content

Fix Docker Security Scanning Errors: Trivy, Scout & More

Fix Database Downloads, Timeouts, and Auth Hell - Fast

Trivy
/troubleshoot/docker-security-vulnerability-scanning/scanning-failures-and-errors
59%
tool
Recommended

pnpm - Fixes npm's Biggest Annoyances

alternative to pnpm

pnpm
/tool/pnpm/overview
59%
tool
Similar content

Bun Production Optimization: Deploy Fast, Monitor & Fix Issues

Master Bun production deployments. Optimize performance, diagnose and fix common issues like memory leaks and Docker crashes, and implement effective monitoring

Bun
/tool/bun/production-optimization
58%
troubleshoot
Similar content

Fix Docker Permission Denied: /var/run/docker.sock Error

Got permission denied connecting to Docker socket? Yeah, you and everyone else

Docker Engine
/troubleshoot/docker-permission-denied-var-run-docker-sock/docker-socket-permission-fixes
56%
integration
Recommended

Node.js Serverless Cold Starts Are Killing Your API Performance

This stack actually fixes it, but here's what you need to know before switching

Bun
/integration/bun-drizzle-hono-typescript/modern-api-development
54%
compare
Recommended

Which Node.js framework is actually faster (and does it matter)?

Hono is stupidly fast, but that doesn't mean you should use it

Hono
/compare/hono/express/fastify/koa/overview
53%
tool
Similar content

Ubuntu 22.04 LTS Developer Workstation Setup & Troubleshooting

Ubuntu 22.04 LTS desktop environment with developer tools, terminal access, and customizable workspace for coding productivity.

Ubuntu 22.04 LTS
/tool/ubuntu-22-04-lts/developer-workstation-setup
51%
tool
Recommended

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)

containerd
/tool/containerd/overview
50%
tool
Similar content

Prometheus Monitoring: Overview, Deployment & Troubleshooting Guide

Free monitoring that actually works (most of the time) and won't die when your network hiccups

Prometheus
/tool/prometheus/overview
50%

Recommendations combine user behavior, content similarity, research intelligence, and SEO optimization