139 docker runtime_error ai_generated partial

container exited with code 139 (segfault)

ID: docker/container-exit-code-139-segfault

Also available as: JSON · Markdown · 中文
70%Fix Rate
82%Confidence
1Evidence
2024-01-10First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
Docker 24.0.7 active
Docker 25.0.0 active
Alpine 3.18 active

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.

generic

中文

容器内的进程尝试访问不允许的内存,通常由于不兼容的二进制架构、内存损坏或内存限制不足。

Official Documentation

https://docs.docker.com/engine/reference/run/#exit-status

Workarounds

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

中文步骤

  1. 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
  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

Dead Ends

Common approaches that don't work:

  1. docker run -m 2g your_image 80% fail

    Increasing memory limit alone does not fix the underlying segfault cause.

  2. docker build --no-cache -t your_image . 70% fail

    Rebuilding the image without fixing architecture mismatch still produces the same binary.

  3. docker run --user root your_image 90% fail

    Running as root does not prevent segfaults caused by memory corruption.