Docker Container exited with code 137
January 18, 2018
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
本文探讨了Docker容器在Mac上因内存不足(表现为退出代码137)而突然终止的问题。作者发现这通常是因为Docker for Mac分配的RAM不足,Linux OOM Killer启动并终止了进程。通过增加Docker的内存分配或设置容器的内存限制,可以有效避免此问题。




8089

被折叠的 条评论
为什么被折叠?



