git - Docker 使用 token 更改 .gitconfig 以进行私有(private) repo 访问

标签 git docker github docker-compose dockerfile

我一直在挖掘以解决访问私有(private)存储库的 docker build 阶段的问题。似乎使用“ token ”是实现此目标的最简单且合理安全的方法。

我遇到了一个 article ,对此进行解释。在评论中,有人建议改进以添加 github token 。我无法让它在 docker 中工作。如何更改 .gitconfig 并让 git 始终使用 token ?

此命令需要更改为使用 token :

RUN echo "[url \"git@github.com:\"]\n\tinsteadOf = https://github.com/" >> /root/.gitconfig

评论:

A better approach would be to generate an api token with read only access to that repo and using something like git config --global url."https://${TOKEN}@github.com/".insteadOf "https://github.com/". This way you don't need a wrapper script or ssh host key checking, nor do you need bake your all access

如果有人能帮我过桥就好了。谢谢

最佳答案

我通过运行以下 RUN 命令解决了这个问题。确保在 github 上生成 token 时拥有正确的权限。

FROM golang:1.9
RUN git config --global url."https://USERNAME:TOKEN@github.com/".insteadOf "https://github.com/"
....

关于git - Docker 使用 token 更改 .gitconfig 以进行私有(private) repo 访问,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47617432/

相关文章:

github - Git 提交未与我的 GitHub 帐户相关联

github - TeamCity 在多 VCS 设置中构建单独的拉取请求

git - 如何从 GitHub 获取 pub 作为依赖

git - 忽略目录 .gitignore 下的所有文件类型

git - 为什么 git 将我的分支名称前缀大写?

git - 如何使用 git 检测复制和粘贴的代码?

docker - 如何在 docker 容器中运行 Symfony 控制台命令

ruby - 从 github 源安装的 Gem 未在 `gem list` 中显示

python - Postgres docker-image 不会运行也不会启动

linux - 存储库 'http://archive.debian.org/debian jessie Release' 未签名