Docker Container exited with code 137
By Pete Freitag
When attempting to fire up a bunch of docker containers using
docker-compose on a Mac, one of the containers was randomly exiting with the exit code 137. The message would look something like this:
container_name exited with code 137
My first reaction was to try to quickly run
docker exec -it container-id /bin/bash and then take a look at the logs, but before I was quick enough to do that I decided to look into exit code 137.
As it turns out this code is commonly associated with Docker for Mac not having enough RAM allocated to it. More specifically the Linux OOM (out of memory) Killer, kicked in and terminated the process.
So it is an easy fix, go to the Docker Menu and select Preferences then the Advanced tab and increase the Memory.
My docker memory was set to 2.0 GB (perhaps the default), I increased it to 4.0 GB and problem solved.
You may also be able to get around this problem by setting the
--memory limit when starting a container, or if you are using docker compose, you can do something like this in your
version: '3' services: your-service-name: image: image-name:tag deploy: resources: limits: memory: 50M reservations: memory: 20M
As it turns out this is not only a problem with Docker on Mac, but you might also find your windows docker containers exited with code 137, and the fix on Windows is going to be the same as on Mac. Simply increase the memory and you should be good to go.
Other causes of exit code 137 on docker
If increasing the memory doesn't fix your exited with code 137 problem, then there are a few other causes of this exit code other than an OOM (out of memory) error:
- External Resource Constraints: If the host system is experiencing resource exhaustion, such as insufficient CPU resources, the Docker daemon may terminate containers to maintain overall system stability.
- Forced termination: if someone / something ran
docker killon the host, or a
killinside the container.
- Invalid Entrypoint or Command: If the container's
CMDis incorrect, or not properly configured, it may cause the container to hang or crash, leading to the dreaded container_name exited with code 137 error message.
What is exit code 137
The linux exit code 137 is a
SIGKILL, it means that the program will be killed immediately without any way to catch the problem, or cleanup resources.
Docker Container exited with code 137 was first published on January 18, 2018.
Weekly Security Advisories Email
Advisory Week is a new weekly email containing security advisories published by major software vendors (Adobe, Apple, Microsoft, etc).