Skip to content

Instantly share code, notes, and snippets.

@jesugmz
Last active November 15, 2022 22:45
Show Gist options
  • Save jesugmz/8b5cb2d78837a984469bb71f3250077e to your computer and use it in GitHub Desktop.
Save jesugmz/8b5cb2d78837a984469bb71f3250077e to your computer and use it in GitHub Desktop.
Docker Hub automated builds with multi-stages

Docker Hub automated builds with multi-stages

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 only
  • prod 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment