在Docker中,git lfs给出错误:的凭据https://github.... 找不到
我正在尝试使用git lfs将大文件从git拉入Docker容器。不幸的是,我一直得到错误:在Docker中,git lfs给出错误:的凭据https://github.... 找不到,git,docker,git-lfs,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
...
---> 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
我还将我的.gittributes
文件和.git
文件添加到Docker图像中
编辑:我是否可以使用:
https://you:password@github.com/you/example.git
或
也许我可以使用https://you:password@github.com/you/example.git
:
这是一种糟糕的做法,因为任何人在构建的映像上执行docker映像历史记录
,都会收回这些凭据
最好进行多阶段构建,如“”中所述
它使用SSH密钥而不是用户名/密码,因为:
- 您可以生成并注册一个专用于docker构建的SSH密钥
- 您可以随时撤销该密钥,因为它仅用于此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 :)
您的编辑是正确的。您可以尝试运行git remote add originhttps://you:password@github.com/you/example.git在您的
pull
行之前。如果由于origin
已经存在而失败,那么您应该修改要复制到容器中的.git
文件。也就是说,运行ssh-keyscan-github.mit.edu>/root/.ssh/known_hosts
,然后运行git-clonehttps://github.mit.edu/user/users-repo.git。但这是一个私有存储库,它是通过企业版的github实现的,所以当我运行东西时,会出现错误:克隆到“users repo”。。。致命:无法读取的用户名'https://github.mit.edu':没有这样的设备或地址
@agaidis是。这就是为什么我建议创建一个专用于该克隆的SSH密钥。使用SSH URL:运行gt克隆git@github.mit.edu/user/users repo.git
现在我得到:克隆到“users repo”。。。警告:已将IP地址“xx.x.xx.xx”的ECDSA主机密钥永久添加到已知主机列表中。@警告:未受保护的私钥文件!@“/root/.ssh/id_rsa”的权限0644太开放。其他人不能访问您的私钥文件。此私钥将被忽略。加载密钥“/root/.ssh/id\u rsa”:权限错误git@github.mit.edu:权限被拒绝(公钥)。致命:无法从远程存储库读取。请确保您具有正确的访问权限,并且存储库存在。
我是否希望执行类似于此stackoverflow帖子中所示的运行chmod 400~/.ssh/id\u rsa
@agaidis是的:权限需要足够严格,SSH才能工作。我通常使用
# 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 :)