title: Dockerfile - How can I declare a variable in a Dockerfile that I can use in multiple RUN instructions?
body: <p>I'm writing a Dockerfile. I want to have a variable that I can pass around to different PowerShell scripts.</p>
  <pre><code>FROM mcr.microsoft.com/windows/servercore/iis
  ENV CONT_IMG_VER test
  RUN echo $CONT_IMG_VER
  </code></pre>
  <p>Outputs</p>
  <pre><code>Step 4/4 : RUN echo $CONT_IMG_VER
   ---&gt; Running in 70c2085d9735
  $CONT_IMG_VER
  </code></pre>
  <p>Instead of</p>
  <pre><code>Step 4/4 : RUN echo $CONT_IMG_VER
   ---&gt; Running in 70c2085d9735
  test
  </code></pre>
  <p><strong>UPDATE</strong>: Per <a href="https://docs.docker.com/engine/reference/builder/#environment-replacement" rel="nofollow noreferrer">Dockerfile reference</a> looks like RUN does not supports ENV.</p>
  <p>How can I declare a variable in a Dockerfile that I can use in multiple RUN instructions?</p>
  <p><a href="https://i.stack.imgur.com/MQTf5.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/MQTf5.png" alt="enter image description here" /></a></p>