Docker构建特定的本地git分支 [英] Docker build specific local git branch

查看:318
本文介绍了Docker构建特定的本地git分支的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是docker的新手,想对我的应用程序的特定git分支进行容器化.如果我运行docker build并提供dockerfile的位置,则会默认从本地master分支构建一个映像.为了能够建立另一个分支,说开发".我已经进行了一些研究,发现的所有答案都建议从特定的远程分支而非特定的本地分支进行构建.

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.

推荐答案

您将以与从非默认分支中从源代码构建或运行任何其他程序相同的方式执行此操作:要在本地运行,然后运行docker build.

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) \
  .

(我需要在日常工作中相当常规地执行此操作:它使我可以检查同事提议的功能分支并自己实际运行它们.执行类似的操作,或者尝试构建昨天代码的Docker映像,而不是今天发生的事情,通常是一个很好的理由,不要在您的Dockerfile中git clone.)

(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.)

这篇关于Docker构建特定的本地git分支的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆