title: Memory Limit and CPU Limit in Docker Container
body: <p>UPDATE:</p>
  
  <p>found a lot of questions and discussions on stackoverflow about this topic. And although they are marked as accepted answered and started by thousands of users, they do not seem to be the right answer here.</p>
  
  <hr>
  
  <p>I ran a docker (version 1.13.1, build 092cba3) container with resource constraints as follows:</p>
  
  <pre><code>docker run --privileged -v /sys/fs/cgroup:/sys/fs/cgroup -m 4096M --cpuset-cpus='0' --cpus=1 --cpu-shares=256 -p $IMAGE_NAME
  </code></pre>
  
  <p>The host system (RHEL 7) has 4 cores and 8G memory. Basically I want to restrict the available memory and CPU for the container. After successfully launched the container, I opened the bash and tried to find the limit information from within the container. But I wasn't able to get the correct information.</p>
  
  <p>I tried this:</p>
  
  <pre><code>sudo cat /proc/meminfo
  </code></pre>
  
  <p>The result is:</p>
  
  <p><strong>Host system</strong>
  MemTotal:        8008812 kB
  MemFree:         7416404 kB
  MemAvailable:    7537332 kB<br>
  <strong>Docker Container</strong>
  MemTotal:        8008812 kB
  MemFree:         7318052 kB
  MemAvailable:    7498764 kB</p>
  
  <p>Similarly, I wanted to get CPU limit:</p>
  
  <pre><code>grep -c ^processor /proc/cpuinfo
  </code></pre>
  
  <p>The result is:</p>
  
  <p><strong>Host system</strong> 4<br>
  <strong>Docker Image</strong> 4</p>
  
  <p>It seems that the CPU and memory limit enforced by container is not visible by the container. I also tried to query cgroup information.</p>
  
  <pre><code>mkdir -p /tmp/memory
  mount -n -t cgroup -o memory cgroup /tmp/memory
  </code></pre>
  
  <p>Then I look into the cgroup files:</p>
  
  <pre><code>[root@engrlab memory]# cat /tmp/memory/memory.limit_in_bytes
  9223372036854771712
  </code></pre>
  
  <p>This number is greater than the actual memory of the host system.</p>
  
  <p>Is there a way to verify that the resource constraints has been correctly set in container? How do I find the resource constraint info from within a container? Appreciate any suggestion.</p>