Configure Automated Builds on Docker Hub

Default Landing Page at https://hub.docker.com

If this is the first time you’re signing in to your Docker Hub account, you need to create your first repository for the docker image. Just like a GitHub code repository, a Docker Hub repository provides you the capability to version your Docker images. So, go ahead and click on the Create a Repository button.

No alt text provided for this image

On the Create Repository page, fill in the repository name and description and select if it is a public or private repository. Note that with a free Hub account, you can have only one private account. Under optional Build Settings, you get options to connect your GitHub or BitBucket account. Since we’re here enable auto triggering of the Docker image builds, let’s go ahead and link GitHub (or, BitBucket) account.

After successfully linking your GitHub account, you can select the repository that you want to link to this build. In this case, let’s select the project that we used in our previous article – SpringBoot Hateoas Demo application.

No alt text provided for this image

Next, we need to define a build rule. This will define how the new Docker images are versioned/tagged. You can get more idea on how these settings work for you, you can refer to the sample Build Rules under View example build rules. For now, I’m going with the Branch source type with my source branch as main (not master) and all other options as given. Click on Create, to create your Build Configuration.

Now, for the repository, under Builds, you should be able to see the newly created configuration.

No alt text provided for this image

Go ahead and trigger your first build by clicking the Trigger button under Automated Builds. Make sure you have provided the valid Source branch name – master or main. Assuming everything is configured properly, your build should successfully be able to generate the Docker image with the configured build rules.

No alt text provided for this image

You can now pull this image – chandanv892/springboot-hateoas-demo – and run a container.

No alt text provided for this image

To verify if the build is indeed triggered automatically upon each change that you push to your code repository, you can push a change and see a new image generated. As you can see below, the new commit bfeb771 has triggered a new build and is in progress.

No alt text provided for this image

Well done! You now have an auto-build configuration that takes care of building new Docker images on every change that you push to your repository.

Stay safe!