2

I'm trying to clone a repository when building an image from a Dockerfile. I'm using the sequenceiq/docker-spark Dockerfile and extending it as follows (before the ENTRYPOINT line):

RUN yum install -y git
RUN git clone git@github.com:myorg/myrepo.git

I get the following error after a few minutes:

Initialized empty Git repository in /myrepo/.git/
fatal: The remote end hung up unexpectedly
INFO[0128] The command [/bin/sh -c git clone git@github.com:myorg/myrepo.git] returned a non-zero code: 128

I've added the image's id_rsa.pub to the Deploy Keys for that repository. I tried running bash on the image and git clone-ing with the same issue. I'm stumped. I found this related issue here but my ssh key is password-less, so it didn't help.

Community
  • 1
  • 1
Cody Canning
  • 176
  • 3
  • 14

2 Answers2

1

I've added the image's id_rsa.pub to the Deploy Keys for that repository.

If you are trying to use ssh keys to authenticate to GitHub, you would need to make the corresponding private key available inside the container during the build process (for example, by copying it into the container with the COPY directive).

For public repositories, the easiest solution is just to use the https:// URL for the repository, rather than accessing it via ssh.

For private repositories, using the https:// URL may also be easiest, and then arranging to provide credentials via the git credentials mechanism (http://git-scm.com/docs/git-credential-store).

larsks
  • 277,717
  • 41
  • 399
  • 399
  • The base image generates a password-less private public key pair. I added that public key from the image to the repository's Deploy Keys, so the corresponding private key is available in `/root/.ssh/id_rsa`. Moreover, I get the same error if I _don't_ add the public key. – Cody Canning Apr 08 '15 at 00:25
0

I think Git may be trying to check the server against known_hosts. Try passing -o CheckHostIP=no -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null to SSH.

There's another question that has good answers about how to pass those values through to Git. Basically, you either need to run Git >2.3 or make a little shell script that calls SSH the way you want and point Git at that.

Community
  • 1
  • 1
Nathaniel Waisbrot
  • 23,261
  • 7
  • 71
  • 99