title: Add private key to ssh-agent in docker file
body: <p>I am trying to write a docker file for angular cli project but I have an external dependency which is a private repo on BitBucket so I need to pass my ssh key. I am trying to pass ssh keys using <code>--build-arg</code></p>
  
  <p>Now issues is, It's not adding those keys to ssh-agent and ask for the password instead.</p>
  
  <p>I am using this command to run
  <code>docker build -t ng-2-docker/client --build-arg ssh_prv_key="$(cat ~/.ssh/id_rsa)" --build-arg ssh_pub_key="$(cat ~/.ssh/id_rsa)" .</code></p>
  
  <p>and this is my docker file</p>
  
  <pre><code>ARG ssh_prv_key
  ARG ssh_pub_key
  
  # Use an official Node runtime as a parent image
  FROM node:8.9.4
  
  # Specify working directory in docker container
  WORKDIR /app
  
  # Authorize SSH Host
  RUN mkdir -p /ssh/
  RUN chmod 0700 /ssh
  
  # Add the keys and set permissions
  RUN echo "$ssh_prv_key" &gt; /ssh/id_rsa &amp;&amp; echo "$ssh_pub_key" &gt; /ssh/id_rsa.pub &amp;&amp; chmod 600 /ssh/id_rsa &amp;&amp; chmod 600 /ssh/id_rsa.pub
  
  # add bitbucket to known hosts
  RUN ssh-keyscan bitbucket.org &gt; /ssh/known_hosts
  
  # Copy SSH key to temp folder to pull new code
  # ADD ~/.ssh/id_rsa /tmp/
  # RUN ssh-agent /tmp
  RUN ls -la /ssh
  
  # check if ssh agent is running or not, if not, run
  RUN eval `ssh-agent -s` &amp;&amp; ssh-add /ssh/id_rsa
  
  # Copy local files into the containers working directory
  COPY package.json /app
  
  # Install dependencies inside container
  RUN npm i
  
  # Copy local files into the containers working directory
  COPY . /app
  
  # Execute Process
  CMD ["npm", "docker:rogers:local"]
  
  # Remove ssh key from temp
  # RUN rm /tmp/id_rsa
  RUN rm -rf /ssh
  
  # expose port
  EXPOSE 4200
  </code></pre>
  
  <p>and here is the output if I run the command mentioned above.</p>
  
  <p><a href="https://i.stack.imgur.com/3tVQM.png" rel="noreferrer"><img src="https://i.stack.imgur.com/3tVQM.png" alt="enter image description here"></a></p>