title: Docker CMD evaluation with ENTRYPOINT
body: <p>I have a Dockerfile that falls into the <code>exec_entry p1_entry /bin/sh -c exec_cmd p1_cmd</code> category in the matrix found in <a href="https://docs.docker.com/engine/reference/builder/#/understand-how-cmd-and-entrypoint-interact" rel="nofollow noreferrer"><em>Understand how CMD and ENTRYPOINT interact</em></a>.  The behavior is not what I'm expecting.  I was expecting <code>/bin/sh -c exec_cmd p1_cmd</code> to evaluate first then get passed into <code>exec_entry p1_entry</code>.  What I am observing is that <code>/bin/sh -c exec_cmd p1_cmd</code> literally gets passed into <code>exec_entry p1_entry</code> which I think is funny.</p>
  
  <p>To provide more context, I am specifically deriving a new Dockerfile from an <a href="https://hub.docker.com/r/gliderlabs/registrator/~/dockerfile/" rel="nofollow noreferrer">existing Dockerfile</a> where the parent has:</p>
  
  <pre><code>ENTRYPOINT ["/bin/registrator"]
  </code></pre>
  
  <p>I want to pass in specific command-line parameters from my Dockerfile:</p>
  
  <pre><code>FROM gliderlabs/registrator:v7
  CMD echo "-ip=$EXTERNAL_IP consul://$CONSUL_HOST"
  </code></pre>
  
  <p>When I run my Docker image in a container:</p>
  
  <pre><code>$ docker run --rm --name=test-registrator --volume=/var/run/docker.sock:/tmp/docker.sock -e "EXTERNAL_IP=&lt;some-ip&gt;" -e "CONSUL_HOST=&lt;some-consul-hostname&gt;:8500" my/registrator
  </code></pre>
  
  <p>I get the following error:</p>
  
  <pre><code>2016/12/28 19:20:46 Starting registrator v7 ...
  Extra unparsed arguments:
    -c echo "-ip=$EXTERNAL_IP consul://$CONSUL_HOST"
  Options should come before the registry URI argument.
  
  Usage of /bin/registrator:
    /bin/registrator [options] &lt;registry URI&gt;
  
  -cleanup=false: Remove dangling services
  -deregister="always": Deregister exited services "always" or "on-success"
  -internal=false: Use internal ports instead of published ones
  -ip="": IP for ports mapped to the host
  -resync=0: Frequency with which services are resynchronized
  -retry-attempts=0: Max retry attempts to establish a connection with the backend. Use -1 for infinite retries
  -retry-interval=2000: Interval (in millisecond) between retry-attempts.
  -tags="": Append tags for all registered services
  -ttl=0: TTL for services (default is no expiry)
  -ttl-refresh=0: Frequency with which service TTLs are refreshed
  </code></pre>
  
  <p>This means that <code>-c echo "-ip=$EXTERNAL_IP consul://$CONSUL_HOST"</code> is literally getting passed into <code>/bin/registrator</code> as the parameter.</p>
  
  <p>Am I doing something wrong or is this a limitation of the use case where <code>/bin/sh -c exec_cmd p1_cmd</code> does not get evaulated first before getting passed into the <code>ENTRYPOINT</code>?  If the latter is true, then can you also explain the usefulness of this use case?</p>