Skip to main content
  1. Posts/

DockerHub: automate your docker images build and push

·450 words·3 mins· loading · loading · ·
Marco Mornati
Author
Marco Mornati
I build, self-host and sometimes break software in production — writing about AI tooling, coding agents and infrastructure.

Overview
#

The DockerHub website was created by Docker to allow developers to automate the Docker images build and push the image into the Docker repository. In this way you don’t need to use your CPU time to build the image and not even your bandwidth to upload the image into the Docker repository to allow others to pull it.

The procedure to configure DockerHub is really simple.

Configuration
#

1) Create a repository pointing to your source repository (GitHub repo):

RepositoryDefinition
and set it as an automated build. It’s not necessary but in this way anytime you are pushing changes to your repository, DockerHub will build the Docker image automatically.
AutomatedBuildDefinition

2) Configure then for your repository the branch and/or tag you want to auto-check for builds.

TriggerBuildDefinition
In the example, which is mine ghostblog configuration, there is a “listener” on the master branch building the latest version of the Docker and a second lister checking tag. If any tag is pushed matching the RegExp into the name: /^v.[0-9.]+$/ an image is built using the same version as the one used into the tagname. Examples:

  • v.0.10.1 tag triggers a build of an image tagged as v.0.10.1
  • update_dockerfile tag is ignored by dockerhub

3) Change your code on the associated GitHub repo and push code (and tags if needed). You can see if any build is started on the Build Details page.

BuildDetailsPage
At the end of the build procedure (depending on your Docker could take only few seconds or hours) you will have the status of the Docker image:
DockerBuildSuccess
Or, in case of errors:
DockerBuildError
You can then click on the failing build to access to the details. Here you can find the build problem and check the build log.
DockerBuildErrorDetails
DockerBuildLog
4) Check on the Tags page to see the available images of your docker. Here you are also able to manage them removing, for example, some old or wrong image.
DockerImages

Building
#

5) As I said at the beginning, all images built using this method are available on the Docker repository. This means you can simply pull the desired image/tag.

sudo docker pull mmornati/docker-ghostblog:v0.10.0

INFO: all images built using this method are “fresh” image. This means that all the intermediate steps are removed for any new build. In my example it is important to have this because one of the steps into the Dockerfile is downloading a file from internet (ghost latest version). If you keep all the build steps there’s no guarantee to have the Ghost’s latest version into your Docker.

# Install Ghost
RUN \
  cd /tmp && \
  wget https://ghost.org/zip/ghost-latest.zip && \
  unzip ghost-latest.zip -d /ghost && \
  rm -f ghost-latest.zip

Conclusion
#

It is easy and quick, isn’t it? :)