Not able to clone private repo using dockerfile

3.6k views Asked by At

I am new to docker, so was trying all basic stuff.

I have used following dockerfile to generate my working docker images

FROM ubuntu:14.04

MAINTAINER Alok Agarwal "alok.alok.com"

RUN apt-get update

#Install git 
RUN apt-get install -y git
RUN mkdir -p /root/.ssh/

ADD id_rsa /root/.ssh/id_rsa

RUN touch /root/.ssh/known_hosts

RUN chmod 700 /root/.ssh/id_rsa

RUN git clone [email protected]:user/user.git

EXPOSE 80

I am able to clone my repo in my local system using ssh but when doing from docker its giving

fatal: Could not read from remote repository.
Please make sure you have the correct access rights and the repository exists.

I have put my id_rsa file same place where my dockerfile reside but still doesnt know why it is continuously failing.

Am I missing any basic step.

Advance Thanks for your time

1

There are 1 answers

8
Roman Kiselenko On BEST ANSWER

Look at my example, I have a private ssh key in the directory where I dockerize app(ssh_keys/id_rsa), and public key I have already upload to the private repo:

FROM ubuntu:14.04

MAINTAINER Alok Agarwal "alok.alok.com"

RUN apt-get update

#Install git 
RUN apt-get install -y git

RUN /bin/bash -l -c "mkdir /root/.ssh"
ADD ssh_keys/id_rsa /root/.ssh/id_rsa
RUN chmod 700 /root/.ssh/id_rsa
RUN echo "Host github.com\n\tStrictHostKeyChecking no\n" >> /root/.ssh/config 
RUN mkdir -p /www/app
RUN git clone [email protected]:my_private_repo/repo.git /www/app