title: Why do I get OOM with Docker?
body: <p>I have Java application, wrapped into Docker and hosted on Amazon ECS.</p>
  
  <p>Main technologies are:</p>
  
  <ul>
  <li>SpringBoot 2</li>
  <li>Java 8</li>
  <li>EC2 VM with 4Gb RAM</li>
  </ul>
  
  <p>Every 1-2 days the application is crashing and waking up again resurrected by amazon service.</p>
  
  <p>Under Docker insect I found the reason:</p>
  
  <p><code>"OOMKilled": true,</code> </p>
  
  <p>I have actuator connected to CloudWatch and I found strange behaviour with memory consumption plot:</p>
  
  <p><a href="https://i.stack.imgur.com/t566v.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/t566v.png" alt="Memory consumption"></a></p>
  
  <p>Those blue peaks are the moments where the application has crashed. </p>
  
  <p>I've read that Java 8 has some problem with reading correctly max memory for host but:</p>
  
  <p>1) Docker is starting with flags that should solves the problem</p>
  
  <p><code>ENTRYPOINT exec java -XX:+UnlockExperimentalVMOptions -XX:+UseCGroupMemoryLimitForHeap -XX:MaxRAMFraction=1 -Xms300M -XX:PermSize100M -Djava.security.egd=file:/dev/./urandom -jar /app.jar</code></p>
  
  <p>2) Anyway VM has 4Gb ram, so ~1.3Gb peaks high, shouldn't kill the application. </p>
  
  <p>3) There wasn't any significant load on server in the moments of peaks </p>