Using SSH keys inside docker container

0 votes

I have an app that executes various fun stuff with Git (like running git clone & git push) and I'm trying to docker-ize it.

I’m having an issue where I need to be able to add an SHH key for the container for the container “user” to be used.

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 http://archive.ubuntu.com/ubuntu 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"]
Jul 18, 2018 in Docker by Kalgi
• 2,620 points
543 views

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

Turns out when using Ubuntu, the ssh_config isn't correct. You need to add

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

to your Dockerfile in order to get it to recognize your ssh key.

answered Jul 18, 2018 by Nilesh
• 6,900 points

Related Questions In Docker

0 votes
1 answer

Different file owner inside Docker container and in host machine Ask

Filesystems, at least in Unix- and Linux-like ...READ MORE

answered Jun 25, 2018 in Docker by Damon Salvatore
• 5,450 points
44 views
0 votes
1 answer

Different file owner inside Docker container and in host machine

Here is what you can try. Since ...READ MORE

answered Jun 27, 2018 in Docker by Atul
• 10,220 points
101 views
0 votes
1 answer

How to run a docker command from inside the container?

You must have come across the /var/run/docker.sock file, ...READ MORE

answered Jun 28, 2018 in Docker by Sophie may
• 9,330 points
241 views
+2 votes
11 answers
+13 votes
2 answers
0 votes
1 answer
0 votes
2 answers

Can't access apache karaf docker container

To access karaf shell directly you can ...READ MORE

answered Aug 6, 2018 in Docker by Nilesh
• 6,900 points
139 views
+1 vote
4 answers

Docker Compose wait for container X before starting Y

You can use the depends_on feature was ...READ MORE

answered May 6 in Docker by Kunal
1,112 views

© 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.