Skip to content

Trigger builds on Docker Hub

gmouchakis edited this page Jul 18, 2016 · 1 revision

This page describes how to automatically update an image in Docker Hub when a repository in GitHub is updated by using Docker Hub triggers and GitHub webhooks. In this scenario the user has a Dockerfile on Docker Hub that contains a "git clone example_repo" instruction, where "example_repo" a repository owned by the user, and the user wants to build a new image each time there is a new commit on "example_repo". To ensure that the Docker build will not break from the latest commit the user has to follow a commit strategy on "example_repo" where only stable releases are committed on the checked out branch in the Dockerfile.

To achieve a fresh build each time a repository is updated follow the steps bellow:

First you have to activate the build triggers on Docker Hub. To do so go to the repository's Docker Hub page and select the "Build Settings" tab. Then in the "Build Triggers" section click on "Activate Triggers". A "Trigger URL" will be created.

Then go to the "example_repo" GitHub page and click on "Settings". Select "Webhooks & services" and click on "Add webhook". In "Payload URL" copy the "Trigger URL" you generated on Docker Hub and click on "Add Webhook".

Now each time a push happens on "example_repo" a build will be triggered on Docker Hub and the "git clone" command will fetch the latest release of "example_repo".

Clone this wiki locally