title: Using variable interpolation in string in Docker
body: <p>I am having trouble creating and using variables in a Dockerfile - I build a Docker image via a Dockerfile with this command:</p>
  
  <pre><code>$ docker build --build-arg s=scripts/a.sh -t a .
  </code></pre>
  
  <p>(So because I use --build-arg, $s will be an available argument in the Dockerfile, and this part works)</p>
  
  <p>The Dockerfile is like so:</p>
  
  <pre><code>ARG s
  
  RUN echo $s 
  
  RUN useradd -ms /bin/bash newuser
  
  USER newuser
  WORKDIR /home/newuser
  
  ENV fn=$(filename $s)  # fails on this line
  
  COPY $s .
  
  ENTRYPOINT ["/bin/bash", "/home/newuser/$fn"]
  </code></pre>
  
  <p>The problem I have is that the Docker build is failing on the line indicated above.</p>
  
  <pre><code>Error response from daemon: Syntax error - can't find = in "$s)". Must be of the form: name=value
  </code></pre>
  
  <p>If I change that line to this:</p>
  
  <pre><code>RUN fn=$(filename $s)
  </code></pre>
  
  <p>I get this error:</p>
  
  <pre><code>Error: Command failed: docker build --build-arg s=scripts/a.sh -t a .
  The command '/bin/sh -c fn=$(filename $s)' returned a non-zero code: 127
  </code></pre>
  
  <p>Anyone know the correct way to</p>
  
  <ol>
  <li>Create a variable inside the docker file</li>
  <li><p>Use string interpolation with that variable so that I can reference the variable in the ENTRYPOINT arguments like so:</p>
  
  <p>ENTRYPOINT ["/bin/bash", "/home/newuser/$var"]</p></li>
  </ol>
  
  <p>Even if I do this:</p>
  
  <pre><code>ARG s
  
  ARG sname
  
  RUN echo $s          # works as expected
  RUN echo $sname      # works as expected
  
  RUN useradd -ms /bin/bash newuser
  
  USER newuser
  WORKDIR /home/newuser
  
  
  COPY $s .  # works as expected (I believe)
  
  ENTRYPOINT /bin/bash /home/newuser/$sname  # does not work as expected
  </code></pre>
  
  <p>even though I am using the "non-JSON" version of ENTRYPOINT, it still doesn't seem to pick up the value for the <code>$sname</code> variable.</p>