Dockerfile 中的 Git 克隆仓库

标签 git github ssh docker

从 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/

相关文章:

GitHub 对 SSH 部署 key 的限制

android - 存储库中的 Flutter 文件夹

javascript - 如何控制所有开发者使用相同的库版本?

git - git:通过提交查看对特定文件的更改

windows - Git 扩展无法识别 Github RSA 签名

python - 如何在 requirements.txt 中声明一个直接的 github 源

git clone 结果为 : "fatal: The remote end hung up unexpectedly"

linux - 从终端 tty 到桌面 session 启动程序。

github - git Push ssh 管道损坏错误/httpcurl ssl 读取错误

git - 如何防止不需要的钩子(Hook)请求?