↓ Skip to main content

How to Fix Docker Exit Code 139 (Segmentation Fault) on Apple Silicon ARM64

How to Fix Docker Exit Code 139 (Segmentation Fault) on Apple Silicon ARM64

I spun up a container on the M-series Mac last week, hit run, and got slapped with Exit Code 139 before the terminal even finished printing. No stack trace, no useful log line — just a dead process and a Segmentation Fault. I went back through my code looking for the bug. There wasn’t one. This one isn’t a logic problem, it’s an architecture problem, and it’s happening below the level where your code even runs.

The Architecture Mismatch
#

If the image you pulled is amd64 and your chip is ARM64, Docker has to translate every instruction on the fly. When that translation layer desyncs — and it does, more than you’d think — the process ends up reading memory it was never supposed to touch, and the kernel kills it with a segfault.

The musl vs. glibc Trap
#

Separate problem, same symptom. Alpine-based images run on musl libc instead of glibc. Most pre-compiled Linux binaries — Python wheels, Node native modules, anything with a C extension — were built expecting glibc’s memory layout. Hand that binary a musl environment instead and it segfaults on first touch, immediately, no warning.

Rosetta 2 Emulation Gaps
#

Docker Desktop leans on Rosetta 2 for x86 translation, and it’s solid for most workloads. But JIT compilers, databases, anything making low-level syscalls — that stuff can slip past Rosetta and fall through to raw QEMU emulation, which is slower and a lot more willing to crash under load.

Fix 1: Force Native Architecture or Turn On Rosetta
#

Open Docker Desktop, go to General, and check “Use Rosetta for x86/amd64 emulation on Apple Silicon.” That alone kills a big chunk of translation-based segfaults. If you’re building locally, pin the target platform explicitly instead of letting Docker guess:

services:
  app:
    image: node:20-alpine
    platform: linux/arm64

Fix 2: Get Off Alpine, or Patch the libc Gap
#

If Exit Code 139 is coming out of an Alpine container, you’ve hit the libc wall. The clean fix is dropping Alpine for Debian Slim or Ubuntu — both ship glibc natively, so the compatibility crash just stops happening. If you’re locked into Alpine for size reasons, add the compat layer instead:

RUN apk add --no-cache libc6-compat

Fix 3: Rebuild Dependencies Inside the Container
#

Never copy node_modules or a .venv from your host into the container if the architectures don’t match — anything compiled on your Mac’s side was built for the wrong target. Run npm install or pip install as part of the container build itself, so everything compiles against the container’s actual architecture. If a Python package only ships an amd64 wheel, force a source build or grab an ARM64-tagged version instead.

Where It Still Breaks
#

Turn Rosetta off and lean on pure QEMU, and memory-heavy work — database migrations, big compiles — will throw 139 from stack overflows inside the emulation layer itself. And Docker Desktop’s VM has a fixed memory ceiling on macOS — if a process under emulation hits that ceiling, the kernel kills it the same way, segfault, no distinction. Bump the allocation to 4GB minimum, 8GB if the stack’s heavy.

Match your architecture, drop musl where it’s fighting you, build native inside the container. That’s the whole fix.

Melvin
Author
Melvin
I am a software developer building high-performance local AI tools and web architectures. I created Sablegrid, a platform that automates project scoping end to end. Stellar Tech Labs is where I write up what I learn along the way.

Related

Comments