<p>I was a little confused with below command:</p>

<pre><code>kubectl run busybox --image=busybox --restart=Never -o yaml --dry-run -- /bin/sh -c 'echo hello;sleep 3600'
</code></pre>

<p>YAML:</p>

<pre><code>apiVersion: v1
kind: Pod
metadata:
  creationTimestamp: null
  labels:
    run: busybox
  name: busybox
spec:
  containers:
  - args:
    - /bin/sh
    - -c
    - echo hello;sleep 3600
    image: busybox
    name: busybox
    resources: {}
  dnsPolicy: ClusterFirst
  restartPolicy: Never
status: {}
</code></pre>

<p>I know if we don't specify parameter <code>--command</code>, then parameters after <code>--</code> will be treated as arguments.</p>

<p>But I wanted to know, how <code>/bin/sh -c "echo hello;sleep 3600"</code> was working in case of arguments? According to Kubernetes documentation(<a href="https://kubernetes.io/docs/tasks/inject-data-application/define-command-argument-container/#notes" rel="noreferrer">https://kubernetes.io/docs/tasks/inject-data-application/define-command-argument-container/#notes</a>), If we specify only arguments in a POD then docker EntryPoint will be used as EntryPoint command. So the resultant command which will be executed in the docker image will be <code>Docker EntryPoint + kubectl arguments</code>.</p>

<p>As Busybox DockerFile does not contain any EntryPoint(<a href="https://github.com/docker-library/busybox/blob/master/musl/Dockerfile" rel="noreferrer">https://github.com/docker-library/busybox/blob/master/musl/Dockerfile</a>), so arguments specified in the kubectl command will only be used, so the command will look like:</p>

<p><code>/bin/sh -c 'echo hello;sleep 3600'</code></p>

<p>And if we specify <code>--command</code>, then according to Kubernetes documentation, DockerFile arguments(CMD) and command(EntryPoint) both will be overridden with command specified in the kubectl command, so it will look similar to above:</p>

<p><code>/bin/sh -c 'echo hello;sleep 3600'</code></p>

<p>So it would be same in the end.</p>

Amit Thakkar
<p>When working with containers in Kubernetes, you should be careful not to mix up Kubenetes <code>command</code> and Docker <code>Cmd</code>.</p>
<ul>
<li>the <code>command</code> field in Kubernetes corresponds to the <code>EntryPoint</code> field in Docker</li>
<li>the <code>args</code> field in Kubernetes corresponds to the <code>Cmd</code> field in Docker</li>
</ul>
<p>From <a href="https://kubernetes.io/docs/tasks/inject-data-application/define-command-argument-container/#notes" rel="noreferrer">Kubernets documentation</a>:</p>
<blockquote>
<p>When you override the default <code>Entrypoint</code> and <code>Cmd</code>, these rules apply:</p>
<ul>
<li><p>If you do not supply <code>command</code> or <code>args</code> for a Container, the defaults
defined in the Docker image are used.</p>
</li>
<li><p>If you supply a <code>command</code> but no <code>args</code> for a Container, only the supplied
<code>command</code> is used. The default <code>EntryPoint</code> and the default <code>Cmd</code> defined in
the Docker image are ignored.</p>
</li>
<li><p>If you supply only <code>args</code> for a Container, the default <code>Entrypoint</code>
defined in the Docker image is run with the <code>args</code> that you supplied.</p>
</li>
<li><p>If you supply a <code>command</code> and <code>args</code>, the default <code>Entrypoint</code> and the
default <code>Cmd</code> defined in the Docker image are ignored. Your <code>command</code> is
run with your <code>args</code>.</p>
</li>
</ul>
</blockquote>
