/ docker

DockerHub: automate your docker images build and push

The DockerHub website it is 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.

1) Create a repository pointing to your source repository (GitHub repo):
and set is as an automate build. It is not necessar but in this way anytime you are pushing changes to your repository, DockerHub will build the Docker image automatically.

2) Configure then for your repository the branch and/or tag you want to auto-check for builds.
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:
an image is built using the same version than the one used into the tagname.

  • 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.
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:
Or, in case of errors:
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.
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.

5) As I said at the begging, all the 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 the images are built as "fresh" image. This means that all the intermediate steps are removed for any new build.
In my example it is important to have this cause, one of the step into the Dockerfile is downloading a file from internet (ghost latest version). If you keep all the build steps you can't be sure to have the Ghost's latest version into your Docker.

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

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