在Docker中,git-lfs提供错误:https:// github ....的凭据未找到

时间:2018-06-25 20:23:24

标签: git docker git-lfs

我正在尝试使用git-lfs将大文件从git中拉到Docker容器中。不幸的是,我不断收到错误消息:

...

 ---> f07e7087dc5a
Step 13/16 : RUN git lfs pull
 ---> Running in a387e389eebd
batch response: Git credentials for https://github.XXXX.edu/XXXXX/XXXXXXXXX.git not found.
error: failed to fetch some objects from 'https://github.XXXX.edu/XXXXX/XXXXXXXXX.git/info/lfs'
The command '/bin/sh -c git lfs pull' returned a non-zero code: 2

有什么办法解决此问题并使我的文件正确无误地拉出吗?我在Docker中运行以下命令,尝试使git-lfs正常工作:

# Get git-lfs and pull down the large files
RUN apt-get update && apt-get install -y apt-utils && apt-get install -y curl
RUN curl -s https://packagecloud.io/install/repositories/github/git-lfs/script.deb.sh | bash
RUN apt-get install -y git-lfs
RUN git lfs install
RUN git lfs pull

我也将.gitattributes文件和.git文件添加到Docker映像中。

编辑:我可以以某种方式使用:

https://you:password@github.com/you/example.git

git config remote.origin.url https://you:password@github.com/you/example.git

1 个答案:

答案 0 :(得分:1)

  

也许我可以使用https://you:password@github.com/you/example.git

这是一个不好的做法,因为任何在构建的映像上执行docker image history的人都会获得这些凭据。

最好进行多阶段构建,如“ Access Private Repositories from Your Dockerfile Without Leaving Behind Your SSH Keys”中所述。

它使用SSH密钥而不是用户名/密码,原因是:

  • 您可以生成并注册专用于Docker构建的SSH密钥。
  • 您可以随时撤消该密钥,因为它仅用于for this docker build(与凭据密码相反,您不能轻易更改它而不会影响使用该密码的其他脚本)

您的Dockerfile如下:

# this is our first build stage, it will not persist in the final image
FROM ubuntu as intermediate

# install git
RUN apt-get update
RUN apt-get install -y git

# add credentials on build
ARG SSH_PRIVATE_KEY
RUN mkdir /root/.ssh/
RUN echo "${SSH_PRIVATE_KEY}" > /root/.ssh/id_rsa

# make sure your domain is accepted
RUN touch /root/.ssh/known_hosts
RUN ssh-keyscan bitbucket.org >> /root/.ssh/known_hosts

RUN git clone git@bitbucket.org:your-user/your-repo.git

FROM ubuntu
# copy the repository form the previous image
COPY --from=intermediate /your-repo /srv/your-repo
# ... actually use the repo :)