Reputation: 31642
docker build can accept the URL of a git repo to find files to build.
But this confuses me because this is the workflow I expect:
* Pull my repo with my code and dockerfile
* Do development
* run docker build using the PATH "context" of the repo on my local drive
* poke/test my app after the container spins up
* Write more code do more builds, etc
If Im building directly from a repo, what does that workflow look like? Would I be committing, pushing to remote and then building? Or is this feature for a pipeline where my build server does docker build from a repo because I thought Im supposed to be passing around "images" for that sort of thing.
Upvotes: 2
Views: 5859
Reputation: 5337
It is useful for continuous integration pipelines. A common use-case for these build pipelines is to first git clone
, then git checkout
some branch, then change into a Docker build context directory, then run the build. That could look something like:
#!/bin/sh
git clone ssh://git.mycompany.example.com/myproject.git
git checkout ${BRANCH}
cd docker
docker build -t "mycompany/myproject:${BRANCH}" .
Since this is a common use-case, a shorthand method of doing the same thing is rolled into docker build
, like so:
#!/bin/sh
docker build -t "mycompany/myproject:${BRANCH}" \
"ssh://git.mycompany.example.com/myproject.git#${BRANCH}:docker"
If you care about the details of how the clone/checkout happens, or doing anything else after checkout, or doing anything beyond the simple case, then you would want to go with the "long" method of coding out each individual step. If you just care that a specific version of a Dockerfile gets built, you can do it in a single shell command.
For local development, you would continue to use either docker build PATH
to build with a build context, or docker build - < Dockerfile
without a context.
An alternate reason to use the URL form is if you want to build an image for a project you are not actively working on. Say you make use of mycompany/coolimage
as a base image. There is a bug in some tool of that base image published on the Docker image repository. The authors of mycompany/coolimage
have fixed this bug on the dev
branch, but this has not yet been published to the image repository. You could sit on your hands and wait for the image to publish; or, you could do docker build -t mycompany/coolimage ssh://git.mycompany.example.com/myproject.git#dev
and continue your work based off the Dockerfile in the dev branch. You could also clone your own copy, but if you are not making any changes, why bother?
Upvotes: 7