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 docker-compose.yml
file:
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 kill
on the host, or akill
inside the container. - Invalid Entrypoint or Command: If the container's
ENTRYPOINT
orCMD
is 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.
Comments
Thank you so much. This article saved lot of time. I increased the Memory and problem fixed.
Thanks for sharing this resolution for the docker container fail issue! I updated the memory settings on my Windows 10 and running fine now. Have a wonderful day!
Thank you, struggled for days with this.
Thank you had 12 containers running and could not figure out why everything was crashing and this solved the problem!
Thanks for this, still saves you headaches in 2020.
Pete, You saved my day with your solution. I was trying to run druid in docker and received this "container_name exited with code 137" many times. With your solution, the problem went away. Thanks! Xingsheng
I spent a lot of time. Thanks to you, I solved this problem.
I increase the Docker memory to 8G, however, I encounter this issue again today. Could it be that I have too many conatiners running? I have druid, kafka, MySQL, debezium, and ksqldb all running in Docker.
Thanks a lot. Worked like a charm. I have this mysterious problem for days. With the same conf other VM run well. Turns out it's a RAM problem. Solved after resizing from 2 to 4 GB.
You saved my day. Thank you!!!
Nearly three years to the day, your article continues to rescue people's sanity everywhere -- many thanks!
Same here, thanks a lot, you saved me maybe another day. It was the memory limit that fixed my problem.
Thanks for sharing. it helped
Thanks, this did the trick!
Thanks a lot !! I was struggling for hours but finally, your blog brought relief
Thanks for sharing, first hit in google and on the spot. After latest docker update on mac the settings were reset causing this issue for me.
Thank you so much, your post helped me fix a long-standing issue.