<p>There are many way to set command in pod.</p>
<pre><code>1.
command: [&quot;/bin/sh&quot;,&quot;-c&quot;,&quot;sleep 1000&quot;]
2.
command: [&quot;/bin/sh&quot;]
args: [&quot;-c&quot;,&quot;sleep 1000&quot;]
3.
args:  [&quot;/bin/sh&quot;,&quot;-c&quot;,&quot;sleep 1000&quot;]
</code></pre>
<p>Are they the same or different?</p>

john chen
<p>These are all almost the same; except that if the underlying image has a Docker <code>ENTRYPOINT</code> then the <code>args:</code> are passed to it as arguments in the third case, without <code>command:</code>.</p>
<p>In core Docker, there are two ways to specify the main container command, the Dockerfile <a href="https://docs.docker.com/engine/reference/builder/#entrypoint" rel="nofollow noreferrer"><code>ENTRYPOINT</code></a> and <a href="https://docs.docker.com/engine/reference/builder/#cmd" rel="nofollow noreferrer"><code>CMD</code></a> directives.  Either or both of these can be overridden when the container starts, but resetting the <code>ENTRYPOINT</code> value always clears <code>CMD</code>.  If both are present then <a href="https://docs.docker.com/engine/reference/builder/#understand-how-cmd-and-entrypoint-interact" rel="nofollow noreferrer">the <code>CMD</code> is passed as arguments to the <code>ENTRYPOINT</code></a>.</p>
<p>Kubernetes has the same concept and uses the same underlying image structure, but its names are different:</p>
<ul>
<li>Kubernetes <code>command:</code> overrides Docker <code>ENTRYPOINT</code> (and resets <code>CMD</code>)</li>
<li>Kubernetes <code>args:</code> overrides Docker <code>CMD</code></li>
</ul>
<p>So in the first case setting <code>command:</code> overrides the container entrypoint and resets the container command to an empty list; in the second you directly set both parts.  In both cases the two lists are combined together and you get an identical 3-word command.</p>
<p>In the last case <code>args:</code> only overrides the container command part.  If the image has a Dockerfile <code>ENTRYPOINT</code> then this list of arguments is passed as arguments to the entrypoint process.</p>
<p>Which one is &quot;right&quot; depends on how the image is constructed:</p>
<ul>
<li><p>Some images use <code>CMD</code> to specify the main command to run and don't have <code>ENTRYPOINT</code>; in this case any of the forms you show will work.</p>
<pre class="lang-bash prettyprint-override"><code>CMD the-main-program
# override with either Kubernetes command: or args:
</code></pre>
</li>
<li><p>Some images use <code>ENTRYPOINT</code> to specify the main command to run (and depending on how they're constructed may completely ignore <code>CMD</code>).  In this case you must use one of the first two forms with <code>command:</code>.</p>
<pre class="lang-bash prettyprint-override"><code>ENTRYPOINT [&quot;the-main-command&quot;]
CMD [&quot;--argument&quot;, &quot;value&quot;]
# override with Kubernetes command: and optionally args:
</code></pre>
</li>
<li><p>Some images use <code>CMD</code> to specify the main container command, and <code>ENTRYPOINT</code> as a wrapper script to do first-time setup.  In this case you need the third form that sets only <code>args:</code> or else the entrypoint script will get skipped.</p>
<pre class="lang-bash prettyprint-override"><code>ENTRYPOINT [&quot;docker-entrypoint.sh&quot;]
CMD [&quot;the-main-command&quot;]
# override with Kubernetes args: only
</code></pre>
</li>
</ul>
