0

In the docker documentation one can see that it is possible to build an image from git repository. It is even possible to make a build from the selected branch and directory. I have a repository with multiple Dockerfiles in a directories structure. They are locally built though with the project root context, so I run:

docker build -f docker/backend/Dockerfile -t mybackend .

and thus I have image built with context of /. But documentation on building from git says, this context is used only on repositories where Dockerfile is in the main project dir.

Is it possible to bypass this somehow? To run command:

docker build -t myimage git@github.com:user/repo.git#branch:docker/backend

and have it built with context of the main directory?

  • try using s2i that is a docker build tool with strong conventions. It does this with a command line flag. You pick a builder image that knows how to build which languages and frameworks you use. I use off the shelf nodejs and php7x builder images but I have also created my own to build R shiny. Learning a new tool is a bit of overhead but it is mature and solved a ton of things like your question. For example if you have microservices then you end up with many dockerfiles to security patch. yet there are security patched s2i images so easier to stay secure. – simbo1905 Jan 29 at 8:54
  • For OKD k8s I wrote a chatbot to check for s2i security patches with code at github.com/UniqKey/openshiftbot/blob/master/bin/imagechecker.sh and picture at slide 8 of slideshare.net/simbo1905/… – simbo1905 Jan 29 at 9:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.