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,680 points
12,672 views

1 answer to this question.

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
• 7,060 points

Related Questions In Docker

0 votes
1 answer

How to enable SSH inside Docker container?

Hi@akhtar, To enable SSH inside Docker Container, you ...READ MORE

answered Jun 4, 2020 in Docker by MD
• 95,460 points
17,643 views
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,980 points
944 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,240 points
1,936 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
• 10,620 points
3,517 views
+15 votes
2 answers

Git management technique when there are multiple customers and need multiple customization?

Consider this - In 'extended' Git-Flow, (Git-Multi-Flow, ...READ MORE

answered Mar 27, 2018 in DevOps & Agile by DragonLord999
• 8,450 points
4,034 views
+2 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
• 7,060 points
2,527 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 7, 2019 in Docker by Kunal
11,226 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP