title: Expand ARG value in CMD [Dockerfile]
body: <p>I'm passing a build argument into: <code>docker build --build-arg RUNTIME=test</code></p>
  
  <p>In my Dockerfile I want to use the argument's value in the CMD:</p>
  
  <p><code>CMD ["npm", "run", "start:${RUNTIME}"]</code></p>
  
  <p>Doing so results in this error: <code>npm ERR! missing script: start:${RUNTIME}</code> - it's not expanding the variable</p>
  
  <p>I read through this post: <a href="https://stackoverflow.com/questions/23071214/use-environment-variables-in-cmd">Use environment variables in CMD</a></p>
  
  <p>So I tried doing: <code>CMD ["sh", "-c", "npm run start:${RUNTIME}"]</code> - I end up with this error: <code>/bin/sh: [sh,: not found</code></p>
  
  <p>Both errors occur when I run the built container.</p>
  
  <p>I'm using the node alpine image as a base. Anyone have ideas how to get the argument value to expand within CMD? Thanks in advance!</p>
  
  <p>full Dockerfile:</p>
  
  <pre><code>FROM node:10.15.0-alpine as builder
  
  ARG RUNTIME_ENV=test
  RUN mkdir -p /usr/app
  WORKDIR /usr/app
  
  COPY . .
  
  RUN npm ci
  RUN npm run build
  
  FROM node:10.15.0-alpine
  
  COPY --from=builder /usr/app/.npmrc /usr/app/package*.json /usr/app/server.js ./
  COPY --from=builder  /usr/app/config ./config
  COPY --from=builder  /usr/app/build ./build
  
  RUN npm ci --only=production
  
  EXPOSE 3000
  
  CMD ["npm", "run", "start:${RUNTIME_ENV}"]
  </code></pre>
  
  <p>Update:
  Just for clarity there were two problems I was running into.
  1. The problem as described by Samuel P.
  2. ENV values are not carried between containers (multi-stage)</p>
  
  <p>Here's the working Dockerfile where I'm able to expand environment variables in CMD:</p>
  
  <pre><code># Here we set the build-arg as an environment variable.
  # Setting this in the base image allows each build stage to access it
  FROM node:10.15.0-alpine as base
  ARG ENV
  ENV RUNTIME_ENV=${ENV}
  
  FROM base as builder
  RUN mkdir -p /usr/app
  WORKDIR /usr/app
  COPY . .
  RUN npm ci &amp;&amp; npm run build
  
  FROM base
  COPY --from=builder /usr/app/.npmrc /usr/app/package*.json /usr/app/server.js ./
  COPY --from=builder  /usr/app/config ./config
  COPY --from=builder  /usr/app/build ./build
  
  RUN npm ci --only=production
  
  EXPOSE 3000
  
  CMD npm run start:${RUNTIME_ENV}
  </code></pre>