我正在尝试使用 git-lfs 将大文件从 git pull 到 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
最佳答案
May be I can use
https://you:password@github.com/you/example.git
:
这是一个不好的做法,因为任何人都在做
docker image history
在您构建的图像上将获得这些凭据。最好进行多阶段构建,如“Access Private Repositories from Your Dockerfile Without Leaving Behind Your SSH Keys”中所述。
它使用 SSH key 而不是用户名/密码,因为:
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 :)
关于git - 在 Docker 中,git-lfs 给出错误 : credentials for https://github. ... 未找到,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51031300/