Prevent Docker containers from crashing with error 137 (2024)

Docker systems can be used fora wide range of applications, from setting up development environments to hosting web instances.

Live Docker containers that crash often can end up ruiningtheirpurpose. As a result, a majorconcern faced by Docker providers is ensuring the containeruptime.

Containers crash due to many reasons, the main issue being lack of enoughmemory. During a crash, container will show an exit code that explains the reason for its crash.

Docker containers crashing often?

CLICK HERE TO SAVE YOUR DOCKER SYSTEM!

Today we’ll see what causes Docker ‘Exited (137)’ crash message and how to fix it.

What causes error 137 in Docker

Docker crashes are often denoted by the message ‘Exited’ in the container ‘STATUS’ when listing the container using ‘docker ps -a’ command.

Error137 in Docker denotes that the container was ‘KILL’ed by ‘oom-killer’ (Out of Memory). This happens when there isn’t enough memory in the container for running the process.

‘OOM killer’ is a proactive process that jumps in to save the system when itsmemory level goes too low, by killing theresource-abusive processes to free up memory for the system.

Here is a snippet that shows that the Mysql container Exited with error 137:

When the MySQL process running in the container exceeded its memory usage, OOM-killer killed the container and it exited with code 137.

[ Running a Docker infrastructure doesn’t have to be hard, or costly. Get world class Docker management services at affordable pricing.]

How to debugerror 137 in Docker

Each Docker container has a log file associated with it. These log files store all the relevant information and updates related to that container.

Examining the container log file is vital in troubleshooting its crash. Details of the crash can be identified by checking the container logs using ‘docker logs’ command.

For the MySQL container that crashed, the log files showed the following information:

Prevent Docker containers from crashing with error 137 (2)

Docker error 137 – Out of memory

The logs in this case clearly shows that the MySQL container was killeddue to the mysqld process taking up too much memory.

Reasonsfor ‘Out of memory’ error 137 in Docker

In Docker architecture, the containers are hosted in a single physical machine. Error 137 in Docker usually happens due to 2 main out-of-memory reasons:

1. Docker container has run out of memory

By default, Docker containers use the available memory in the host machine. To prevent asingle container from abusing the host resources, we set memory limits per container.

But if the memory usage by the processes in the container exceeds this memory limit set for the container, the OOM-killer would kill the applicationand the container crashes.

An application can use up too much memory due to improper configuration, service not optimized, high traffic or usage or resource abuse by users.

Prevent Docker containers from crashing with error 137 (3)

Docker system architecture

2. Docker hosthasno free memory

The memory limit that can be allotted to the Docker containers is limited by the total available memory in the host machine which hosts them.

Many often, when usage and traffic increases, the available free memory may be insufficientfor all the containers.As a result, containers may crash.

[ Never let your business be affected by crashing containers!Our Docker experts take care of your infrastructure and promptly resolves all container issues.]

How to resolveerror 137 in Docker

When a Docker container exits with OOM error, it shows that there is a lack of memory. But, the first resort should not be to increase the RAM in the host machine.

Improperly configuredservices, abusive processes or peak traffic can lead to memory shortage. So the first option is to identify the cause of this memory usage.

After identifying the cause, the following corrective actions can be done in the Docker system to avoid further such OOM crashes.

1. Optimize the services

Unoptimized applicationscould take up more than optimalmemory.For instance, an improperly configured MySQL service can quickly consume the entire host memory.

So, the first step is to monitor the application running in the container and to optimize the service. This can be done by editing the configuration file or recompiling the service.

2. Mount config files from outside

It is always advisable to mount theconfig files of services from outside the Docker container. This will allow to edit them easily without recompiling the Docker image.

For instance, in MySQL docker image, “/etc/mysql/conf.d” can be mounted as a volume. Any configuration changes for MySQL service can be done without affecting thatimage.

3. Monitorthe container usage

Monitoring the container’s memory usage to detectabusive users, resource-depleted processes, traffic spikes, etc. is very vital in Docker system management.

Depending on the traffic and resource usage of processes, memory limitsfor the containers can be changed to suit their business purpose better.

4. Add more RAM to the host machine

After optimizing the services and setting memory limits, if thecontainers are running at their maximum memory limits, then we should add more RAM.

Adding more RAM and ensuring enough swapmemory in the host machine would help the containers to utilize that memory whenever there is a memory crunch.

In short..

Today we saw how to fix error 137 in Dockerusinga systematic debugging method.But there may be scenarios where the error code may not be displayed, especially when the container is launched from some shell script.

At Bobcares, examining Docker logs, optimizing applications, limiting resource usage for containers, monitoring the traffic, etc. areroutinely done to avoid crashes.

Before deploying Docker containers for live hosting or development environment setup, we perform stress test by simulating the estimated peak traffic.

This helps us to minimize crashes in the live server.If you’d like to know how to manage your Dockerresources efficiently for your business purpose, we’d behappy to talk to you.

Related posts:

  1. How to clear Docker cache and save disk space
  2. Docker container logs for quick troubleshooting
  3. Setting up Docker hosting in oVirt using Docker Swarm and Shipyard
  4. Want multiple Docker containers on the same port? Here’s how

Looking for a stable Docker setup?

Talk to our Docker specialists today to know how we can keep your containers top notch!

CLICK HERE FOR URGENT FIX!

var google_conversion_label = "owonCMyG5nEQ0aD71QM";

Prevent Docker containers from crashing with error 137 (2024)

FAQs

Prevent Docker containers from crashing with error 137? ›

What exit code 137 means for Kubernetes​ Exit code 137 is a signal that occurs when a container's memory exceeds the memory limit provided in the pod specification. When a container consumes too much memory, Kubernetes kills it to protect it from consuming too many resources on the node.

What is exit code 137 for container? ›

What exit code 137 means for Kubernetes​ Exit code 137 is a signal that occurs when a container's memory exceeds the memory limit provided in the pod specification. When a container consumes too much memory, Kubernetes kills it to protect it from consuming too many resources on the node.

What is exit code 137 in Docker PIP? ›

Exit code 137 means the container was exited because it received a termination signal. If it's caused by an out of memory kill, you should find evidence in the docker logs. See Read the daemon logs | Docker Docs for how to access the logs.

What is exit status 137 while performing build while running engine? ›

Exit Code 137 means that the container has received a SIGKILL signal from the host operating system. This signal instructs a process to terminate immediately, with no grace period. This can be either: Triggered when a container is killed via the container engine, for example when using the docker kill command.

What is exit code 137 on AWS container stopped? ›

Common exit codes

1: Refers to application error. For more information, review application logs. 137: Occurs when the Task was forced to exit (SIGKILL) for the container. If you don't respond to a SIGTERM within a default 30-second period, then the SIGKILL value is sent and containers are forcibly stopped.

What is error code 137 in docker build? ›

The exit code 137 returned by npm command usually indicates a memory allocation issue, where npm is exceeding the current available memory in the environment. Looking at the logs you shared with us, it seems like you are executing the npm command as part of a docker build (the npm command is inside a Dockerfile).

What is exit code 137 server crash? ›

137 means OOM killer killed your process because it was using too much memory. Possible fixes: Add more memory to system.

What is error code 137 in pip? ›

The exit code 137 typically indicates that your process was killed due to running out of memory. Since you're using an Apple M1 Pro with 8GB RAM and the memory usage spikes to 45GB, it's likely that your system is terminating the training process to prevent memory overflow.

What is exit code 137 in Jenkins docker? ›

In cases where virtual memory is running short the kernel OutOfMemoryError killer may forcibly kill Jenkins or individual builds. If this occurs on Linux you may see builds terminate with exit code 137 ( 128 + signal number for SIGKILL ).

What is exit code 137 in Gitlab CI docker? ›

The build step does not have enough memory to finish building. You can get an overview of your build resources by clicking in the metrics tab in the build screen. The error usually happens when Docker does not have enough memory, but it can also appear if there is not enough disk space.

What is process exit code 137 crashed tests? ›

The error 137 is a process crash - it's not an orchestrator failure. The crash is invoked intentionally by our extension code because it has detected a timeout trying to access the storage account via the Azure Storage SDK. The connection between the memory usage and the Storage SDK is not clear.

What is subprocess exited with error 137? ›

When a subprocess is started, but is terminated externally (e.g., using kill -9 ), Bun executes the entire script normally until its end, but terminates the process with code 137 if this subprocess was previously called (using fetch , for example), even if it all worked properly.

What is the difference between exit code 143 and 137? ›

At the Kubernetes level, you will see the Kubernetes error by running kubectl describe pod . At the container level, you will see the exit code – 143 if the container terminated gracefully with SIGTERM, or 137 if it was forcefully terminated after the grace period.

What is exit code 137 in container? ›

Two main reasons for exit code 137: Resource Limitation: The container ran out of memory (OOM) on the host machine. External Termination: The container was forcefully terminated with SIGKILL.

What is container from a bad node on host exit status 137? ›

The error message "Exit code is 137" usually means that the container exceeded its memory limit or was manually terminated. There are several steps you can take to find the problem: Monitor memory usage in the Spark UI to determine if certain nodes are out of memory.

What is exit code 137 in AWS batch? ›

When a container (Spark executor) runs out of memory, YARN automatically kills it. This causes the "Container killed on request. Exit code is 137" error. These errors can happen in different job stages, both in narrow and wide transformations.

What is exit code 137 in cargo? ›

Exit code 137 is SIGKILL, which can be caused by an OOM kill, but doesn't necessarily have to be caused by it.

What is exit code 137 signal? ›

The exit code 137 typically indicates that your process was killed due to running out of memory. Since you're using an Apple M1 Pro with 8GB RAM and the memory usage spikes to 45GB, it's likely that your system is terminating the training process to prevent memory overflow.

What is YARN container exited with a non zero exit code 137? ›

When a container (Spark executor) runs out of memory, YARN automatically kills it. This causes the "Container killed on request. Exit code is 137" error. These errors can happen in different job stages, both in narrow and wide transformations.

What is CI exit code 137? ›

It means that a container got a SIGKILL signal, usually because Kubernetes' Out Of Memory (OOM) killer had to stop it from using too much memory. This stops the container from using up all the memory, keeping the system stable.

References

Top Articles
Latest Posts
Article information

Author: Jamar Nader

Last Updated:

Views: 6372

Rating: 4.4 / 5 (75 voted)

Reviews: 82% of readers found this page helpful

Author information

Name: Jamar Nader

Birthday: 1995-02-28

Address: Apt. 536 6162 Reichel Greens, Port Zackaryside, CT 22682-9804

Phone: +9958384818317

Job: IT Representative

Hobby: Scrapbooking, Hiking, Hunting, Kite flying, Blacksmithing, Video gaming, Foraging

Introduction: My name is Jamar Nader, I am a fine, shiny, colorful, bright, nice, perfect, curious person who loves writing and wants to share my knowledge and understanding with you.