Docker build specific local git branch

吃可爱长大的小学妹 提交于 2019-12-11 05:49:21

问题


I am new to docker and would like to containerize a specific git branch of my app.If I run docker build and give the location of my dockerfile, an image will be build but from the local master branch by default.I want to be able to build another branch say "develop".I have done some research and all the answers I found suggest building from a specific remote branch and not a specific local branch.


回答1:


You’d do this the same way you’d build or run any other program, from source, from a non-default branch: check out the branch you want to run locally, then run docker build.

git clone git@github.com:myname/project
cd project
git checkout branchname
docker build \
  -t myname/project:branchname-g$(git rev-parse --short HEAD) \
  .

(I need to do this fairly routinely in my day job: it lets me check out my colleague’s proposed feature branches and actually run them myself. Doing things like this, or trying to build a Docker image of yesterday’s code and not the thing that broke today, tends to be a pretty good reason to not git clone from within your Dockerfile.)



来源:https://stackoverflow.com/questions/56793996/docker-build-specific-local-git-branch

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!