Pete Freitag Pete Freitag

Docker Container exited with code 137

linuxwebapple

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.

Adjust docker memory to fix exited with code 137 error

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

Like this? Follow me ↯

Docker Container exited with code 137 was first published on January 18, 2018.


Want Security Advisories via Email?

Advisory Week is a new weekly email containing security advisories published by major software vendors (Adobe, Apple, Microsoft, etc).

Comments

Thank you so much. This article saved lot of time. I increased the Memory and problem fixed.
by Vishal Garg on 05/07/2018 at 7:09:04 AM UTC
Thank you!
by Keith Davis on 10/29/2018 at 6:06:40 PM UTC
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!
by Srini on 06/12/2019 at 2:23:45 PM UTC
Thank you, struggled for days with this.
by Thomas Knee on 08/14/2019 at 8:43:24 AM UTC
Thank you had 12 containers running and could not figure out why everything was crashing and this solved the problem!
by Josh on 12/16/2019 at 4:27:13 AM UTC
Thanks for this, still saves you headaches in 2020.
by Tobias on 04/23/2020 at 11:05:00 AM UTC
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
by Xingsheng on 07/01/2020 at 7:16:27 PM UTC
I spent a lot of time.
Thanks to you, I solved this problem.
by korean on 07/24/2020 at 1:52:00 AM UTC
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.
by Xingsheng Qian on 08/13/2020 at 6:06:05 PM UTC
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.
by azzamsa on 09/09/2020 at 4:17:50 AM UTC
You saved my day. Thank you!!!
by Anonymous on 10/08/2020 at 10:16:22 PM UTC
Nearly three years to the day, your article continues to rescue people's sanity everywhere -- many thanks!
by Concordian on 01/06/2021 at 2:52:16 PM UTC
Same here, thanks a lot, you saved me maybe another day. It was the memory limit that fixed my problem.
by Anonymous on 01/12/2021 at 12:53:32 AM UTC
Thanks for sharing. it helped
by Anonymous on 01/17/2021 at 5:55:08 PM UTC
Thanks, this did the trick!
by Andrew on 01/19/2021 at 2:19:39 PM UTC
Thanks a lot !! I was struggling for hours but finally, your blog brought relief
by Priya on 02/19/2021 at 11:48:40 PM UTC
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.
by Kiran on 02/23/2021 at 1:36:10 AM UTC
Thank you so much, your post helped me fix a long-standing issue.
by Padmini on 03/25/2021 at 8:06:20 PM UTC
Thank you so much. My problem was solved.
by Trung Vu on 04/02/2021 at 2:28:29 AM UTC
Thanks you. It worked and saved lot of time and effort.
by Vishal on 04/23/2021 at 6:37:22 PM UTC