使用 docker-compose 从私有 GitHub 存储库构建 Docker 镜像

zep*_*lee 2 docker docker-compose

我知道可以提供 GitHub HTTP URL 作为服务的构建上下文:

version: '3.9'

services:
  my-app:
    build: https://github.com/rambo/my-app.git
Run Code Online (Sandbox Code Playgroud)

上述方法对于公共回购来说效果很好。但是,如果Dockerfile存储在需要身份验证(例如通过 SSH)的私人存储库中该怎么办?支持类似下面的示例吗?

services:
  my-app:
    build: ssh://git@github.com:rambo/my-app.git
Run Code Online (Sandbox Code Playgroud)

我已经尝试了上述配置的多种变体,但似乎没有任何效果。

Raj*_*ath 5

是的,您可以通过使用仅具有读取访问权限的 github个人访问令牌来实现此目的https://docs.github.com/en/free-pro-team@latest/github/authenticating-to-github/creating-a-personal -访问令牌

然后你的令牌就是你的用户名和空密码

例如,https://{token}@github.com/org_name/repo.git