代码之家  ›  专栏  ›  技术社区  ›  peachykeen

在Docker中,Git LFS给出错误:找不到https://github…的凭据

  •  1
  • peachykeen  · 技术社区  · 6 年前

    我正在尝试使用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 回复  |  直到 6 年前
        1
  •  1
  •   VonC    6 年前

    可能是我可以用的 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 (与凭据密码相反,您无法轻松更改,而不会影响使用所述密码的其他脚本)

    你的档案看起来像:

    # 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 :)