Docker Hub automated builds are nice to build automatically Docker images when code is pushed to the linked git repository but they do not support Docker multi-stages by default.
To do so is needed to override the default commands that Docker Hub uses internally by using hooks.
In this example we have two stages:
dev
will be built from master branch onlyprod
will be built per git tag
Check here the content of the Dockerfile.
To build and push the custom stages we have to create hooks for each command:
In this example a Makefile was used to normalize the usage of the Docker commands but a raw docker build
and docker push
can be used.
According to the documentation, is needed that the folder hooks is at the same level of our Dockerfile. Check the example repository folder structure for more clarity.
Once our hooks are in the git repository, Docker Hub will use them and we will get our images using Docker multi-stages.