I assume that you have a GitHub and Docker Hub accounts. Also I assume that you have your application repository in GitHub and don't have the image in Docker Hub yet. Now we will see how to automatically build docker image in our Docker Hub account after pushing code changes to our GitHub repository. Our GitHub repository name is called inanzzz/hello_php and we don't have the image in Docker Hub account yet. For more information read Configure automated builds on Docker Hub page.


Structure


hello$ tree
.
├── app
│   ├── a.php
│   └── b.php
├── docker
│   ├── docker-compose.yml
│   ├── .env
│   └── php
│   └── Dockerfile
└── Readme.md

3 directories, 5 files

Link Accounts


Go to your Docker Hub account and click "Link Accounts" button under "Create > Create Automated Build" menu option. Follow the instructions to finish linking. This is a very easy process.


Create Automated Build


Docker Hub


  1. Go to your Docker Hub account and click "Create Auto-build" button under "Create > Create Automated Build" menu option.

  2. Click the name of the GitHub repository in next page.

  3. Click "Create Automated Build" in the next page.

  4. Click the "Click here to customize" link.

  5. Fill in the form. Type: Branch, Name: Master, Dockerfile Location: /docker/php, Docker Tag Name: latest. This will rebuild the image when git push event takes place in GitHub and tag the image with latest. You can see the image tagged as latest under "Tags" tab.

  6. Click "Activate Trigers" button. This will create a "Trigger URL". Copy it for now.

GitHub


  1. Go to your GitHub account and select your project.

  2. Click "Settings" tab.

  3. Click "Webhooks" link.

  4. Click "Add Webhook" button.

  5. Paste the "Trigger URL" you generated on Docker Hub in "Payload URL" field.

  6. Tick "Just the push event" option.

  7. Click "Add Webhook" button.

As soon as you complete GitHub steps above, Docker Hub will start building. You can check it under "Build Details" tab in Docker Hub.