Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker: how to build an image from a non-master branch on Github repository

Is it possible to build an image from a non-master branch on a Github repository?

For example, I have the repository //github.com/myAccount/docker-myImage with a branch development that I would like to use for my image. Unfortunately, the following command only seems to allow building from the master branch:

docker build -t myAccount/myImage git://github.com/myAccount/docker-myImage

Here is the relevant documentation from man docker build:

Building an image using a URL

This will clone the specified Github repository from the URL and use it as context. The Dockerfile at the root of the repository is used as Dockerfile. This only works if the Github repository is a dedicated repository.

docker build github.com/scollier/Fedora-Dockerfiles/tree/master/apache

Note: You can set an arbitrary Git repository via the git:// schema.

Perhaps there is an alternative, like docker build -t myAccount/myImage git://github.com/myAccount/docker-myImage:development?

like image 895
modulitos Avatar asked Dec 29 '14 05:12

modulitos


People also ask

How do I create a docker image from an existing image?

You can create a new image by using docker command $docker build -f docker_filename . , It will first read the Dockerfile where the instructions are written and automatically build the image. The instruction in the Dockerfile contains the necessary commands to assemble an image.

Can GitHub actions build Docker image?

GitHub Action to build and push Docker images with Buildx with full support of the features provided by Moby BuildKit builder toolkit. This includes multi-platform build, secrets, remote cache, etc. and different builder deployment/namespacing options.


2 Answers

docker build -t myAccount/myImage https://github.com/myAccount/docker-myImage.git#development

See docker build command reference for more options.

like image 118
michielbdejong Avatar answered Sep 17 '22 20:09

michielbdejong


I proposed this question on #docker at the Freenode IRC and the user scollier contacted me and he said that he'll get back to me about this issue. I believe he is involved with the Docker documentation that I mentioned in my questions. In the meantime, I found a workaround by adding the following to my Dockerfile:

RUN git clone something && cd something && git checkout branch

This solution seems to solve all my needs. Thanks for the support!

like image 23
modulitos Avatar answered Sep 19 '22 20:09

modulitos