Segmentation Fault (SIGSEGV)
Exit code 139 (128 + 11 for SIGSEGV) indicates a segmentation fault. This is a critical error where the application inside the container attempted to access a memory address that it was not allowed to access, causing the operating system to terminate it immediately for protection.
- 1A bug in the application code, often related to pointers or memory management in languages like C/C++/Go/Rust.
- 2An incompatibility between a native library used by the application and the container's base OS (e.g., glibc vs. musl).
- 3Corrupted application binaries or shared libraries within the container.
- 4Using a base image with a different architecture than the application was compiled for (e.g., ARM code on an x86_64 host).
A C++ application tries to dereference a null pointer.
// main.cpp
int main() {
int* ptr = nullptr;
*ptr = 42; // This will cause a segmentation fault
return 0;
}
// Compile and run this in a container
// g++ main.cpp -o my_app
// ./my_app
// echo $? --> 139expected output
Segmentation fault (core dumped)
Fix 1
Debug Application Code
WHEN The error is reproducible and likely caused by a software bug.
# Rebuild the image with debug symbols # RUN g++ -g main.cpp -o my_app # Run with a debugger like GDB docker run -it --cap-add=SYS_PTRACE your-image gdb ./my_app
Why this works
Running the application with a debugger allows you to pinpoint the exact line of code that is causing the illegal memory access.
Fix 2
Ensure Base Image Compatibility
WHEN Using pre-compiled binaries or native extensions (e.g., in Node.js or Python).
# For Alpine Linux, rebuild native modules RUN npm rebuild --build-from-source # Or match the OS you built on # FROM ubuntu:22.04 (if binaries were built on Ubuntu)
Why this works
Different Linux distributions use different standard libraries (like glibc on Ubuntu vs. musl on Alpine). Binaries must be compiled against the same library they will run with.
✕ Ignore the error and set the container to always restart.
A segmentation fault is a serious bug. Automatically restarting the container will hide the problem and could lead to data corruption or unpredictable behavior.
Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev