<p>Trying to run a pod based on an image with this <code>Dockerfile</code>:</p>
<pre><code>...

ENTRYPOINT [ &quot;./mybashscript&quot;, &quot;;&quot;, &quot;flask&quot; ]
CMD [ &quot;run&quot; ]
</code></pre>
<p>I would be expecting the full command to be <code>./mybashscript; flask run</code>.
However, in this example, the <code>pod</code> / <code>container</code> executes <code>./mybashscript</code> but not <code>flask</code>.</p>
<p>I also tried a couple of variations like:</p>
<pre><code>...

ENTRYPOINT [ &quot;/bin/bash&quot;, &quot;-c&quot;, &quot;./mybashscript &amp;&amp; flask&quot; ]
CMD [ &quot;run&quot; ]
</code></pre>
<p>Now, <code>flask</code> gets executed but <code>run</code> is ignored.</p>
<p>PS: I am trying to understand why this doesn't work and I am aware that I can fit all into the <code>entrypoint</code> or shove everything inside the <code>bash</code> script, but that is not the point.</p>

<p>In both cases you show here, you use the JSON-array <a href="https://docs.docker.com/engine/reference/builder/#exec-form-entrypoint-example" rel="nofollow noreferrer">exec form</a> for <code>ENTRYPOINT</code> and <code>CMD</code>.  This means no shell is run, except in the second case where you run it explicitly.  The two parts are just <a href="https://docs.docker.com/engine/reference/builder/#understand-how-cmd-and-entrypoint-interact" rel="nofollow noreferrer">combined together into a single command</a>.</p>
<p>The first construct runs the script <code>./mybashscript</code>, which must be executable and have a valid &quot;shebang&quot; line (probably <code>#!/bin/bash</code>).  The script is passed three arguments, which you can see in the shell variables <code>$1</code>, <code>$2</code>, and <code>$3</code>: a semicolon <code>;</code>, <code>flask</code>, and <code>run</code>.</p>
<p>The second construct runs <code>/bin/sh -c './mybashscript &amp;&amp; flask' run</code>.  <code>sh -c</code> takes a single argument, which is <code>mybashscript &amp;&amp; flask</code>; the remaining argument <code>run</code> is interpreted as a positional argument, and the <code>sh -c</code> command would see it as <code>$0</code>.</p>
<hr />
<p>The arbitrary split of <code>ENTRYPOINT</code> and <code>CMD</code> you show doesn't really make sense.  The only really important difference between the two is that it is easier to change <code>CMD</code> when you run the container, for example by putting it after the image name in a <code>docker run</code> command.  It makes sense to put all of the command in the command part, or none of it, but not really to put half of the command in one part and half in another.</p>
<p>My first pass here would be to write:</p>
<pre class="lang-sh prettyprint-override"><code># no ENTRYPOINT
CMD ./mybashscript &amp;&amp; flask run
</code></pre>
<p>Docker will insert a <code>sh -c</code> wrapper for you in bare-string <a href="https://docs.docker.com/engine/reference/builder/#shell-form-entrypoint-example" rel="nofollow noreferrer">shell form</a>, so the <code>&amp;&amp;</code> has its usual Bourne-shell meaning.</p>
<hr />
<p>This setup looks like you're trying to run an initialization script before the main container command.  There's a reasonably standard pattern of using an <code>ENTRYPOINT</code> for this.  Since it gets passed the <code>CMD</code> as parameters, the script can end with <code>exec &quot;$@&quot;</code> to run the <code>CMD</code> (potentially as overridden in the <code>docker run</code> command).  The entrypoint script could look like</p>
<pre class="lang-sh prettyprint-override"><code>#!/bin/sh
# entrypoint.sh
./mybashscript
exec &quot;$@&quot;
</code></pre>
<p>(If you wrote <code>mybashscript</code>, you could also end it with the <code>exec &quot;$@&quot;</code> line, and use that script as the entrypoint.)</p>
<p>In the Dockerfile, set this wrapper script as the <code>ENTRYPOINT</code>, and then whatever the main command is as the <code>CMD</code>.</p>
<pre class="lang-sh prettyprint-override"><code>ENTRYPOINT [&quot;./entrypoint.sh&quot;] # must be a JSON array
CMD [&quot;flask&quot;, &quot;run&quot;]           # can be either form
</code></pre>
<p>If you provide an alternate command, it replaces <code>CMD</code>, and so the <code>exec &quot;$@&quot;</code> line will run that command instead of what's in the Dockerfile, but the <code>ENTRYPOINT</code> wrapper still runs.</p>
<pre class="lang-sh prettyprint-override"><code># See the environment the wrapper sets up
docker run --rm your-image env
# Double-check the data directory setup
docker run --rm -v $PWD/data:/data your-image ls -l /data
</code></pre>
<hr />
<p>If you <em>really</em> want to use the <code>sh -c</code> form and the split <code>ENTRYPOINT</code>, then the command inside <code>sh -c</code> has to read <code>$@</code> to find its positional arguments (the <code>CMD</code>), plus you need to know the first argument is <code>$0</code> and not <code>$1</code>.  The form you show would be functional if you wrote</p>
<pre class="lang-sh prettyprint-override"><code># not really recommended but it would work
ENTRYPOINT [&quot;/bin/sh&quot;, &quot;-c&quot;, &quot;./mybashscript &amp;&amp; flask \&quot;$@\&quot;&quot;, &quot;flask&quot;]
CMD [&quot;run&quot;]
</code></pre>
