How to use SSH keys inside docker container

0 votes

I am having an application which executes various fun stuff with Git like running git clone & git push and I'm trying to containerise it.

I am facing an issue in which I need to be able to add an SSH key to the container for the container 'user' to use.

I tried copying it into /root/.ssh/, changing $HOME, creating a git ssh wrapper, and still no luck.

Here is the Dockerfile for reference:

#DOCKER-VERSION 0.3.4                                                           

from  ubuntu:12.04                                                              

RUN  apt-get update                                                             
RUN  apt-get install python-software-properties python g++ make git-core openssh-server -y
RUN  add-apt-repository ppa:chris-lea/node.js                                   
RUN  echo "deb precise universe" >> /etc/apt/sources.list
RUN  apt-get update                                                             
RUN  apt-get install nodejs -y                                                  

ADD . /src                                                                       
ADD ../../home/ubuntu/.ssh/id_rsa /root/.ssh/id_rsa                             
RUN   cd /src; npm install                                                      

EXPOSE  808:808                                                                 

CMD   [ "node", "/src/app.js"]

Can anyone help me with this query?


Oct 8, 2018 in DevOps & Agile by shubham
• 6,480 points

1 answer to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
0 votes

Here is a solution you can try.

It seems that when using Ubuntu, the ssh_config is not correct. You need to add

RUN  echo "    IdentityFile ~/.ssh/id_rsa" >> /etc/ssh/ssh_config

to your  dockerfile in order to get it to recognise your ssh key.

I hope it would help you resolve your query.

answered Oct 8, 2018 by Damon Salvatore
• 5,250 points

Related Questions In DevOps & Agile

+13 votes
5 answers

How do I run a cron job inside a docker container

If you can SSH into your server ...READ MORE

answered Jul 27, 2018 in DevOps & Agile by Kalgi
• 35,640 points
0 votes
1 answer

How to edit file after I shell to a docker container?

Since docker images are trimmed to bare minimum ...READ MORE

answered Sep 11, 2018 in DevOps & Agile by Damon Salvatore
• 5,250 points
0 votes
1 answer
0 votes
1 answer
+13 votes
2 answers
0 votes
1 answer
0 votes
1 answer

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.