Tennis Smith
Tennis Smith

Reputation: 491

Can a docker build use the url of a git branch?

According to the docs, a git url can be passed to a build command: enter image description here

But what happens if the git url needs to be a branch name? In other words, how do I do the equivalent of this:

git clone -b my-firefox-branch [email protected]:creack/docker-firefox.git

Upvotes: 13

Views: 11698

Answers (3)

RzR
RzR

Reputation: 3186

Well it works more or less depending on versions

For recent versions : (docker-engine 1.5.0-0~trusty and+)

docker build https://github.com/rzr/iotjs.git#master
docker build https://github.com/rzr/iotjs.git
docker build github.com/rzr/iotjs.git

For older ones: (docker.io 1.4-5ubuntu1 and -)

docker build https://github.com/rzr/iotjs.git
docker build git://github.com/rzr/iotjs.git
docker build github.com/rzr/iotjs.git

Maybe this can be handled in helper script like:

curl -sL https://rawgit.com/rzr/iotjs/master/run.sh | bash -x -

Upvotes: 1

michielbdejong
michielbdejong

Reputation: 1107

Start your URL with git:// (or https://) and simply append the branch name after #.

I just forked the OP's repo and created a branch to confirm it works (docker version 1.11.1):

root@box:~# docker build git://github.com/michielbdejong/docker-firefox#michielbdejong-patch-1
Sending build context to Docker daemon 52.22 kB
Step 1 : FROM ubuntu:12.04
12.04: Pulling from library/ubuntu
4edf76921243: Downloading
[==========>                                        ] 9.633 MB/44.3 MB
^Croot@box:~# 

See https://docs.docker.com/engine/reference/commandline/build/ for full docs.

Upvotes: 7

shawnzhu
shawnzhu

Reputation: 7585

So far, No. it can't.

Here's what I got:

$ docker build [email protected]:shawnzhu/docker-ruby.git#branch1
2014/12/04 08:19:04 Error trying to use git: exit status 128 (Cloning into '/var/folders/9q/bthxttfj2lq7jtz0b_f938gr0000gn/T/docker-build-git859493111'...
fatal: remote error: 
   is not a valid repository name
  Email [email protected] for help
)

If you take a look at this line of docker CLI code, it only do recursive git clone against given URL of a git repo (even no --depth=1) when using docker build <git-repo-url>.

However, it could be an interesting improvement to docker (if people want it) since #<branch-name> and #<commit> are popular syntax to github URL adopted by lots of tools like npm and bower.

Upvotes: 2

Related Questions