title: Docker argument to a RUN echo command
body: <p>As part of a Dockerfile, I am attempting to modify a text file (ssh_config) to contain a variable passed through by the user (as an ARG) to the docker container at build time.</p>
  
  <p>In my Dockerfile I have (this is not the entire file):</p>
  
  <pre><code>ARG key_name
  RUN echo 'Host geoserver\n\
  User user\n\
  HostName 38.191.191.111\n\
  IdentityFile /root/$key_name' &gt;&gt; /etc/ssh/ssh_config
  </code></pre>
  
  <p>This collects the argument key_name, and then appends some text to the ssh_config text file.</p>
  
  <p>This is run as follows:</p>
  
  <pre><code>docker build --build-arg key_name=GC -t pyramid .
  </code></pre>
  
  <p>When I check to see what has been written, the key_name variable hasn't been parsed, and instead has been written as text (so literally as $key_name).  Obviously I want it to be replaced with the variable passed through ARG.</p>
  
  <p>I have tried using <code>${key_file}</code> instead of just <code>$key_file</code>, I just get the same text in the text file but with curly braces included.</p>
  
  <p>So my question is, how can I use the ARG variable correctly within the RUN echo statement?</p>