Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

docker

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

like image 424
Tennis Smith Avatar asked Aug 26 '14 15:08

Tennis Smith


2 Answers

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.

like image 147
michielbdejong Avatar answered Oct 18 '22 18:10

michielbdejong


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.

like image 40
shawnzhu Avatar answered Oct 18 '22 19:10

shawnzhu