In Docker, git-lfs giving error: credentials for https://github.... not found

In Docker, git-lfs giving error: credentials for https://github.... not found

我正在尝试使用 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

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 密钥而不是 username/password 因为:

  • 您可以生成并注册专用于您的 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 :)