title: Docker uses all memory and crashes the system
body: <p>I have an AWS t2.micro EC2 instance with docker on it, and I bring up the following instances;</p>
  
  <ul>
  <li><a href="https://github.com/jwilder/nginx-proxy" rel="nofollow">jwilder/nginx-proxy</a></li>
  <li><a href="https://hub.docker.com/_/mysql/" rel="nofollow">mysql</a></li>
  <li><a href="https://hub.docker.com/_/wordpress/" rel="nofollow">wordpress</a></li>
  </ul>
  
  <p>Which results in something like this <code>docker stats</code>;</p>
  
  <pre><code>CONTAINER   MEM USAGE/LIMIT     MEM % 
  wordpress   331.9 MB/1.045 GB   31.77%
  nginx       18.32 MB/1.045 GB   1.75% 
  mysql       172.1 MB/1.045 GB   16.48%
  </code></pre>
  
  <p>Then, I run <a href="https://www.joedog.org/siege-home/" rel="nofollow">siege's</a> default 15 concurrent connections against it, which spawns multiple apache processes, reaching the memory limit of the EC2 instance, crashing docker and bash due to no more memory, requiring my intervention to get it all running again.</p>
  
  <p>I have a couple of questions regarding this.</p>
  
  <ol>
  <li>Am I expecting too much?  Should this setup be able to handle 15 concurrent connections?  If so, what changes* need to be made? </li>
  <li>How can I automate recovery from this?  Is there a way to detect that memory is reaching capacity and do something (like reject requests or similar) until memory usage decreases?  Is there a way to keep the system stable during the high request volume so once it's over it does not require my intervention to bring it back up?</li>
  </ol>
  
  <p>* I've already done <a href="http://www.tocker.ca/2014/03/10/configuring-mysql-to-use-minimal-memory.html" rel="nofollow">this</a> to drop mysql memory from 22% to 15%.</p>