spring-guides / gs-spring-boot-docker

Spring Boot with Docker :: Learn how to create a Docker container from a Spring Boot application with Maven or Gradle

Home Page:https://spring.io/guides/gs/spring-boot-docker/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Suggested Dockerfile doesn't take Docker/Java8 memory issue into account

fransvanbuul opened this issue · comments

There's a memory issue with running JVM inside a Docker container: for calculating heap size, it takes the memory size of the host into account, instead of the memory size of the container. This has been fixed in Java 9 and backported to Java 8u131. Detailed info on Carlos Sanchez' weblog.

I personally ran into this issue when creating a bunch of Spring Boot services, running them on Kubernetes and seeing them getting OOMKilled because of memory behavior.

There's a fix available in the form of a couple of new JVM flags. I'd like to suggest to add these to the Dockerfile that's included in this guide, so the entrypoint would look like:
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom", "-XX:+UnlockExperimentalVMOptions", "-XX:+UseCGroupMemoryLimitForHeap", "-jar", "/app.jar"]

(I'm not as sure about also using -XX:MaxRAMFraction=1 as mentioned in the blog.)

If agreed, I'll happily provide a pull request including this change to the Dockerfile and some notes.

Obsolete since JDK 8u225 (I believe).