<p>I'm composing yaml file for scripts running in docker and orchestrated by kubernetes. Is there a way to evaluate the resource utilization for a specicific command or docker, or what's the best practice to set the limit of cpu and mem for pods?</p>
<p><strong>Edit</strong></p>
<p>Most of these scripts will run in a short time, so it's hard to get the resource info. I just wanna try to find a tool to get the maximum usage of cpu and mem, the tool works like <code>time</code>, to print out the execution time.</p>

Yang
<p>You can view statistics for container(s) using the <code>docker stats</code> command.</p>

<p>For example;</p>

<pre><code>docker stats containera containerb

CONTAINER           CPU %               MEM USAGE / LIMIT     MEM %               NET I/O               BLOCK I/O
containera          0.00%               24.15 MB / 1.041 GB   2.32%               1.8 MB / 79.37 kB     0 B / 81.92 kB
containerb          0.00%               24.95 MB / 1.041 GB   2.40%               1.798 MB / 80.72 kB   0 B / 81.92 kB
</code></pre>

<p>Or, see processes running in a container using <code>docker top &lt;container&gt;</code></p>

<pre><code>docker top containera
UID                 PID                 PPID                C                   STIME               TTY                 TIME                CMD
root                4558                2850                0                   21:13               ?                   00:00:00            sh -c npm install http-server -g &amp;&amp; mkdir -p /public &amp;&amp; echo "welcome to containera" &gt; /public/index.html &amp;&amp; http-server -a 0.0.0.0 -p 4200
root                4647                4558                0                   21:13               ?                   00:00:00            node /usr/local/bin/http-server -a 0.0.0.0 -p 4200
</code></pre>

<h3>Limiting resources</h3>

<p>Docker compose (like docker itself) allows you to set limits on resources for a container, for example, limiting the maximum amount of memory used, cpu-shares, etc.</p>

<p>Read this section in the <a href="https://docs.docker.com/compose/compose-file/#cpu-shares-cpuset-domainname-entrypoint-hostname-ipc-mac-address-mem-limit-memswap-limit-privileged-read-only-restart-stdin-open-tty-user-working-dir" rel="nofollow">docker-compose yaml reference</a>, and the docker run reference on <a href="https://docs.docker.com/engine/reference/run/#runtime-constraints-on-resources" rel="nofollow">"Runtime constraints on resources"</a></p>
