Jakim
Jakim

Reputation: 1813

Why docker container always be killed

I am trying to run docker container to start a springboot restful api:

docker run api:latest

Then it exits with error code 137, and printed a "Killed" at the end:

2018-05-19 13:36:08.571  INFO 8 --- [           main] o.s.j.e.a.AnnotationMBeanExporter        : Registering beans for JMX exposure on startup
2018-05-19 13:36:08.581  INFO 8 --- [           main] o.s.c.support.DefaultLifecycleProcessor  : Starting beans in phase 0
2018-05-19 13:36:08.737  INFO 8 --- [           main] b.c.e.u.UndertowEmbeddedServletContainer : Undertow started on port(s) 8080 (http)
2018-05-19 13:36:08.751  INFO 8 --- [           main] org.smarter.Application                  : Started Application in 8.63 seconds (JVM running for 9.454)
Killed

I didn't specify any resource limit to it, why it's exited with error code 137?

Upvotes: 2

Views: 2059

Answers (1)

VonC
VonC

Reputation: 1327784

If your Docker image is running a JDK8u131+ or JDK9+, check "Running a JVM in a Container Without Getting Killed" from Carlos Sanchez.
A JDK would default in most cases to a max heap of 1/4 of the host memory, not the container.

Try, as in this spring-boot-web-docker Dockerfile, to add

ENV JAVA_OPTS "-XX:+UnlockExperimentalVMOptions -XX:+UseCGroupMemoryLimitForHeap -XX:MaxRAMFraction=1 -XshowSettings:vm"

(building your own custom image on top of the one you are trying to use)

Those options come from "Java SE support for Docker CPU and memory limits" (May 2017).

Upvotes: 1

Related Questions