git - 在 Github 包注册表中绑定(bind) Docker 镜像以更正 Github 提交

标签 git docker github github-package-registry

使用 docker push 将包发布到 Github 包注册表时,似乎该包链接到主分支上的最新提交。但是,我目前正在不同的分支上或特定标签上构建我的包。有没有办法将发布的图像绑定(bind)到特定的 git 提交,以便链接到图像的源代码 Assets 是正确的?

最佳答案

帮助页面“Configuring Docker for use with GitHub Package Registry”提到:

Push the image to GitHub Package Registry:

$ docker push docker.pkg.github.com/OWNER/REPOSITORY/IMAGE_NAME:VERSION

所以只要你已经从任何你想要的 Git 提交中构建并标记了你的图像, docker push step 独立于所述 Git 提交:它仅依赖于您构建的内容。
您可以将变量添加到您的 docker build包括 Git 信息。
参见 How to Tag Docker Images with Git Commit Information 中的“Scott Lowe
docker build -t flask-local-build --build-arg GIT_COMMIT=$(git log -1 --format=%h) .
docker inspect flask-local-build | jq '.[].ContainerConfig.Labels'

关于git - 在 Github 包注册表中绑定(bind) Docker 镜像以更正 Github 提交,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57583915/

相关文章:

git - 如何删除不需要的提交和 merge

git - IntelliJ Git 集成插件 : ^0 appended to branch name when checkout is attempted

在远程分支列表下 merge 和删除分支后仍然可以看到 Git Branch

git - 存储库中的全局 .gitignore 与 .gitignore

python - .gitignore 符号中的 "py[cod]"和 "pyc"有什么区别?

linux - 用于 Linux 的 Visual SVN 差异和比较工具

docker - 为什么 “docker push”不只发布Dockerfile?

mysql - 更改 Docker 容器中的 mysql 密码

node.js - 两个Git存储库,一个Docker镜像

git - 使用 Github for Windows 多次克隆同一个存储库