简体   繁体   English

Docker:如何从Github存储库上的非主分支构建映像

[英]Docker: how to build an image from a non-master branch on Github repository

Is it possible to build an image from a non-master branch on a Github repository? 是否可以从Github存储库上的非主分支构建映像?

For example, I have the repository //github.com/myAccount/docker-myImage with a branch development that I would like to use for my image. 例如,我有一个存储库//github.com/myAccount/docker-myImage有一个分支development ,我想用于我的图像。 Unfortunately, the following command only seems to allow building from the master branch: 不幸的是,以下命令似乎只允许从master分支构建:

docker build -t myAccount/myImage git://github.com/myAccount/docker-myImage

Here is the relevant documentation from man docker build : 以下是man docker build的相关文档:

Building an image using a URL 使用URL构建图像

This will clone the specified Github repository from the URL and use it as context. 这将从URL克隆指定的Github存储库并将其用作上下文。 The Dockerfile at the root of the repository is used as Dockerfile. 存储库根目录下的Dockerfile用作Dockerfile。 This only works if the Github repository is a dedicated repository. 这仅在Github存储库是专用存储库时才有效。

 docker build github.com/scollier/Fedora-Dockerfiles/tree/master/apache 

Note: You can set an arbitrary Git repository via the git:// schema. 注意:您可以通过git:// schema设置任意Git存储库。

Perhaps there is an alternative, like docker build -t myAccount/myImage git://github.com/myAccount/docker-myImage:development ? 也许有一个替代方案,比如docker build -t myAccount/myImage git://github.com/myAccount/docker-myImage:development

docker build -t myAccount/myImage https://github.com/myAccount/docker-myImage.git#development

有关更多选项,请参阅docker build命令参考

The doc that you quoted itself mentions how you can specify the branch: 您引用的文档提到了如何指定分支:

github.com/scollier/Fedora-Dockerfiles/tree/master/apache

Change tree/master to the branch you want and see. tree/master更改为您想要的分支并查看。

I proposed this question on #docker at the Freenode IRC and the user scollier contacted me and he said that he'll get back to me about this issue. 我在Freenode IRC的#docker上提出了这个问题,用户scollier联系了我,他说他会回复我这个问题。 I believe he is involved with the Docker documentation that I mentioned in my questions. 我相信他参与了我在问题中提到的Docker文档。 In the meantime, I found a workaround by adding the following to my Dockerfile : 在此期间,我通过在Dockerfile添加以下内容找到了一种解决方法:

RUN git clone something && cd something && git checkout branch

This solution seems to solve all my needs. 这个解决方案似乎解决了我的所有需求。 Thanks for the support! 感谢您的支持!

It seems you need to create the branch before the docker container's git implementation can pull it from origin: 看来你需要在docker容器的git实现从原点拉出它之前创建分支:

git fetch
git checkout -b branch_name
git pull origin branch_name

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM