title: 'docker run' ignores first command appended to ENTRYPOINT ["/bin/bash", "-c", ". foo.sh"] but not ["bash", "foo.sh"]
body: <p>I am trying to run a docker image which executes a bash script and passes run-time arguments to that bash script. I have found that when I build the image using the recommended <code>ENTRYPOINT ["/bin/bash", "-c", ". foo.sh"]</code> entrypoint, the first argument appended to the <code>docker run</code> command doesn't get picked up by my script, but when I build the image with <code>ENTRYPOINT ["bash", "foo.sh"]</code>, it does.</p>
  
  <p>A toy version of the shell script looks like this:</p>
  
  <pre><code>#!/bin/bash
  
  echo you got "$#" args
  ARG1=${1:-foo}
  ARG2=${2:-bar}
  ARG3=${3:-1}
  ARG4=${4:-$(date)}
  
  echo "$ARG1"
  echo "$ARG2"
  echo "$ARG3"
  echo "$ARG4"
  </code></pre>
  
  <p>so basically the script expects up to 4 command line arguments that each have default values.</p>
  
  <p>The original Dockerfile I tried looks like this:</p>
  
  <pre><code>FROM ubuntu
  
  COPY foo.sh foo.sh
  
  ENTRYPOINT ["/bin/bash", "-c", ". foo.sh"]
  </code></pre>
  
  <p>and was based on a number of resources I found for how to properly execute a shell script using the <em>exec</em> form of ENTRYPOINT <a href="https://docs.docker.com/engine/reference/builder/#entrypoint" rel="nofollow noreferrer">recommended by docker</a>.</p>
  
  <p>After building this image with <code>docker build -t foo .</code>, I run it with <code>docker run -it foo first second third fourth</code> and I get the following output:</p>
  
  <pre><code>you got 3 args
  second
  third
  fourth
  Tue Jul  2 13:14:52 UTC 2019
  </code></pre>
  
  <p>so clearly the first argument appended to the <code>docker run</code> command is dropped somewhere along the line, and the only arguments that get ingested by the shell command are the second, third, and fourth. </p>
  
  <p>I spent ages trying to diagnose the issue, and so far haven't figured out why this is happening. The best I've come up with is somewhat of a hacky workaround, after discovering that changing the entrypoint to simply <code>ENTRYPOINT ["bash", "pilates.sh"]</code> produces the desired results.</p>
  
  <p>I would love to know the following: 1. Why does the original entrypoint drop the first run-time argument? 2. Why does the second entrypoint work any differently than the first?</p>