从 Dockerfile 构建镜像时,我正在尝试克隆存储库。我正在使用 sequenceiq/docker-spark Dockerfile并将其扩展如下(在 ENTRYPOINT
行之前):
RUN yum install -y git
RUN git clone git@github.com:myorg/myrepo.git
几分钟后我收到以下错误:
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
我添加了图片的
id_rsa.pub
到该存储库的部署 key 。我尝试运行 bash
在图片上和 git clone
-ing 有同样的问题。我难住了。我发现了这个相关问题 here但是我的 ssh key 是无密码的,所以它没有帮助。
最佳答案
I've added the image's id_rsa.pub to the Deploy Keys for that repository.
如果您尝试使用 ssh key 对 GitHub 进行身份验证,则需要在构建过程中使相应的私钥在容器内可用(例如,通过使用
COPY
指令将其复制到容器中)。对于公共(public)存储库,最简单的解决方案就是使用
https://
存储库的 URL,而不是通过 ssh 访问它。对于私有(private)仓库,使用
https://
URL 也可能是最简单的,然后通过 git 凭据机制 (http://git-scm.com/docs/git-credential-store) 安排提供凭据。
关于Dockerfile 中的 Git 克隆仓库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29502370/