git - 在 Docker 中,git-lfs 给出错误 : credentials for https://github. ... 未找到

标签 git docker git-lfs

我正在尝试使用 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 而不是用户名/密码,因为:
  • 您可以生成并注册一个专用于您的 docker 构建的 SSH key 。
  • 您可以随时撤销该 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/

    相关文章:

    docker - 用不同的环境变量重启docker

    spring - 从docker run命令运行时,来自Docker的图像无法按预期工作

    带有 LFS 的 Git bundle

    git - 未安装 Git LFS 时会发生什么?

    具有开发和生产环境的 Git

    linux - 将我自己的 Git 服务器与我的 Windows Eclipse IDE 链接起来

    ubuntu - 在 Ubuntu 16.04 上以不安全模式运行 docker 注册表时出现问题

    jenkins 中的 Git LFS 设置

    git - 我可以从另一个加载一个 .gitconfig 文件吗?

    git - 您应该在哪个目录或文件路径中运行 eval ssh-agent?