2

I'm trying to add automate a script that requires daily cloning of some git repo.

I basically followed what i found and tried this:

COPY id_rsa /root/.ssh/id_rsa

RUN yum install -y git

RUN eval "$(ssh-agent -s)" && \
    ssh-add /root/.ssh/id_rsa && \
    git clone <my repo>

Where id_rsa is basically a copy of my private key that i've put under the directory where my docker file gets run. k

However, it seems that git still won't allow me to clone:

Identity added: /root/.ssh/id_rsa (/root/.ssh/id_rsa)
Agent pid 13
Initialized empty Git repository in /test/.git/
Host key verification failed.
fatal: The remote end hung up unexpectedly

Any help is much appreciated. Thanks!

user1948847
  • 955
  • 1
  • 12
  • 27
  • Possible duplicate of [Clone private git repo with dockerfile](https://stackoverflow.com/questions/23391839/clone-private-git-repo-with-dockerfile) – David Maze Nov 02 '18 at 21:45
  • 1
    ...but you're much better off doing git operations outside Docker: you don't risk leaking your private key into the image, and you're guaranteed that Docker's image caching won't defeat your `git clone` step. – David Maze Nov 02 '18 at 21:45
  • yes , this seems to be anti pattern , but if u need to do this , check and ensure that chmod 600 on private key – Ijaz Ahmad Nov 02 '18 at 22:36

0 Answers0