# container exited with code 139 (segfault)

- **ID:** `docker/container-exit-code-139-segfault`
- **Domain:** docker
- **Category:** runtime_error
- **Error Code:** `139`
- **Verification:** ai_generated
- **Fix Rate:** 70%

## Root Cause

A process inside the container attempted to access memory it was not allowed to, often due to incompatible binary architecture, corrupted memory, or insufficient memory limits.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| Docker 24.0.7 | active | — | — |
| Docker 25.0.0 | active | — | — |
| Alpine 3.18 | active | — | — |

## Workarounds

1. **Check binary architecture compatibility: run 'file /path/to/binary' inside container. If mismatch, rebuild for correct architecture (e.g., use --platform linux/amd64).** (85% success)
   ```
   Check binary architecture compatibility: run 'file /path/to/binary' inside container. If mismatch, rebuild for correct architecture (e.g., use --platform linux/amd64).
   ```
2. **Increase memory limit and add swap: docker run -m 512m --memory-swap 1g your_image** (65% success)
   ```
   Increase memory limit and add swap: docker run -m 512m --memory-swap 1g your_image
   ```
3. **If using gdb or valgrind, debug the segfault: docker run --cap-add=SYS_PTRACE --security-opt seccomp=unconfined your_image gdb /path/to/binary** (70% success)
   ```
   If using gdb or valgrind, debug the segfault: docker run --cap-add=SYS_PTRACE --security-opt seccomp=unconfined your_image gdb /path/to/binary
   ```

## Dead Ends

- **docker run -m 2g your_image** — Increasing memory limit alone does not fix the underlying segfault cause. (80% fail)
- **docker build --no-cache -t your_image .** — Rebuilding the image without fixing architecture mismatch still produces the same binary. (70% fail)
- **docker run --user root your_image** — Running as root does not prevent segfaults caused by memory corruption. (90% fail)
