Sync up Docker Hub and GitHub to build images automatically

We are going to Sync up Docker Hub and GitHub to build images automatically, it will help us to work with our DevOps team, keeping our different versions, sharing our job with developers and operators, and deploy really fast all our new images. The new images could be consumed for differents PAAS, as OpenShift or Oracle Cloud Platform as a Service (PaaS).

Let´s start:

Create a GitHub account, it is really easy, visit ” https://github.com/” and create your new account.

  • Create your new repository in GIT > New repository > Add your custom name and description:

Upload your dockerfile and resource to our new GitHub Repositoy

  • Our dockerfile and resources are now in GIT.

Now create a Docker Hub account, it is really easy, visit “https://hub.docker.com” and create your new account.

  • Link your DockerHub With GitHub repository > Settings > Linked Account & Services.
    • We will link with Github, so let´s go with GitHub

  • Select Public and Private.

  • Sign in with your GitHub account

  • The connetion has been created
  • From Docker Hub, we will build our images based on a Dockerfile, our Dockerfile and resources will be in GitHub, if we modifiy our dockerfile or our resources, Docker Hub will create a new image automactly based on the new files. So let´s create the Automate build. Click on “Create Automated Build” > Create Auto-build (Github)

  • Select the branch that you created in GIT. In my case, it was “LiferayCommunityEditionPortal7.0.3”.  You should add a description, then you will be able to  finally create the “Automated Build”

  • Our Automated Build has been created.

  • From “Build Settings” set  the Dockerfile Location. In our case / and Trigger the build

  • The build has started, check it from the tag “Build Details”

  • After some minutes, check that the build has been created successfully. If there is any error, fix possible errors in your dockerfile.

  • From the dockerfile tag you will be able to see your dockerfile.

  • Now if we modify our Dockerfile or resources in our GitHub repository, a new build will start automatically and we will have a new image.
    • Let´s add the “parameter maintainer” in our Dockerfile, as an example. “MAINTAINER felixcentmerino.wordpress.com”, and commit the changes to GitHub.
      • Edit the Dockerfile
      • git add Dockerfile
      • git commit -m “blablabla”
      • git push origin master

  • The new build has started.

  • After some minutes, the status should be Success and the new Image is ready to use for all your team.

  • As a public repository, from wherever, anyone of your team can download and use the new image.