2014-06-01 16:48:04 -04:00
page_title: Automated Builds on Docker Hub
page_description: Docker Hub Automated Builds
page_keywords: Docker, docker, registry, accounts, plans, Dockerfile, Docker Hub, docs, documentation, trusted, builds, trusted builds, automated builds
2014-08-09 07:55:47 -04:00
2014-06-01 16:48:04 -04:00
# Automated Builds on Docker Hub
2014-04-15 02:01:25 -04:00
2014-06-30 21:28:25 -04:00
## About Automated Builds
2014-04-15 02:01:25 -04:00
2014-08-09 07:55:47 -04:00
*Automated Builds* are a special feature of Docker Hub which allow you to
use [Docker Hub's ](https://hub.docker.com ) build clusters to automatically
2015-02-03 23:17:56 -05:00
create images from a specified `Dockerfile` and a GitHub or Bitbucket repository
2014-08-09 07:55:47 -04:00
(or "context"). The system will clone your repository and build the image
described by the `Dockerfile` using the repository as the context. The
resulting automated image will then be uploaded to the Docker Hub registry
and marked as an *Automated Build* .
2014-04-15 02:01:25 -04:00
2014-06-30 21:28:25 -04:00
Automated Builds have several advantages:
2014-04-15 02:01:25 -04:00
2014-08-09 07:55:47 -04:00
* Users of *your* Automated Build can trust that the resulting
image was built exactly as specified.
2014-04-15 02:01:25 -04:00
2014-08-09 07:55:47 -04:00
* The `Dockerfile` will be available to anyone with access to
your repository on the Docker Hub registry.
2014-05-21 18:35:10 -04:00
2014-08-09 07:55:47 -04:00
* Because the process is automated, Automated Builds help to
make sure that your repository is always up to date.
2014-04-15 02:01:25 -04:00
2014-08-09 07:55:47 -04:00
Automated Builds are supported for both public and private repositories
on both [GitHub ](http://github.com ) and [Bitbucket ](https://bitbucket.org/ ).
2014-06-30 21:28:25 -04:00
2014-08-09 07:55:47 -04:00
To use Automated Builds, you must have an [account on Docker Hub](
http://docs.docker.com/userguide/dockerhub/#creating-a-docker-hub-account)
and on GitHub and/or Bitbucket. In either case, the account needs
to be properly validated and activated before you can link to it.
2014-06-30 21:28:25 -04:00
## Setting up Automated Builds with GitHub
In order to set up an Automated Build, you need to first link your
2014-08-09 07:55:47 -04:00
[Docker Hub ](https://hub.docker.com ) account with a GitHub account.
This will allow the registry to see your repositories.
2014-04-15 02:01:25 -04:00
2014-06-01 16:48:04 -04:00
> *Note:*
2014-06-30 21:28:25 -04:00
> Automated Builds currently require *read* and *write* access since
2014-06-01 16:48:04 -04:00
> [Docker Hub](https://hub.docker.com) needs to setup a GitHub service
2014-06-30 21:28:25 -04:00
> hook. We have no choice here, this is how GitHub manages permissions, sorry!
> We do guarantee nothing else will be touched in your account.
2014-04-15 02:01:25 -04:00
2014-08-09 07:55:47 -04:00
To get started, log into your Docker Hub account and click the
"+ Add Repository" button at the upper right of the screen. Then select
2014-06-30 21:28:25 -04:00
[Automated Build ](https://registry.hub.docker.com/builds/add/ ).
2014-04-15 02:01:25 -04:00
2014-06-01 16:48:04 -04:00
Select the [GitHub service ](https://registry.hub.docker.com/associate/github/ ).
2014-05-21 18:35:10 -04:00
2014-08-09 07:55:47 -04:00
Then follow the onscreen instructions to authorize and link your
GitHub account to Docker Hub. Once it is linked, you'll be able to
choose a repo from which to create the Automatic Build.
2014-05-21 18:35:10 -04:00
2014-06-30 21:28:25 -04:00
### Creating an Automated Build
2014-04-15 02:01:25 -04:00
2014-08-09 07:55:47 -04:00
You can [create an Automated Build](
https://registry.hub.docker.com/builds/github/select/) from any of your
public or private GitHub repositories with a `Dockerfile` .
2014-04-15 02:01:25 -04:00
2014-08-09 07:55:47 -04:00
### GitHub Submodules
2014-08-04 14:12:01 -04:00
2014-08-12 18:21:55 -04:00
If your GitHub repository contains links to private submodules, you'll
need to add a deploy key from your Docker Hub repository.
2014-08-04 14:12:01 -04:00
2014-08-09 07:55:47 -04:00
Your Docker Hub deploy key is located under the "Build Details"
2014-08-12 18:21:55 -04:00
menu on the Automated Build's main page in the Hub. Add this key
to your GitHub submodule by visiting the Settings page for the
2014-08-09 07:55:47 -04:00
repository on GitHub and selecting "Deploy keys".
2014-08-04 14:12:01 -04:00
< table class = "table table-bordered" >
< thead >
< tr >
< th > Step< / th >
< th > Screenshot< / th >
< th > Description< / th >
< / tr >
< / thead >
< tbody >
< tr >
< td > 1.< / td >
< td > < img src = "/docker-hub/hub-images/deploy_key.png" > < / td >
2014-08-12 18:21:55 -04:00
< td > Your automated build's deploy key is in the "Build Details" menu
under "Deploy keys".< / td >
2014-08-04 14:12:01 -04:00
< / tr >
< tr >
< td > 2.< / td >
< td > < img src = "/docker-hub/hub-images/github_deploy_key.png" > < / td >
2014-08-12 18:21:55 -04:00
< td > In your GitHub submodule's repository Settings page, add the
deploy key from your Docker Hub Automated Build.< / td >
2014-08-04 14:12:01 -04:00
< / tr >
< / tbody >
< / table >
2014-08-09 07:55:47 -04:00
### GitHub Organizations
2014-04-15 02:01:25 -04:00
2014-06-30 21:28:25 -04:00
GitHub organizations will appear once your membership to that organization is
2014-04-15 02:01:25 -04:00
made public on GitHub. To verify, you can look at the members tab for your
organization on GitHub.
2014-08-09 07:55:47 -04:00
### GitHub Service Hooks
2014-04-15 02:01:25 -04:00
2014-08-09 07:55:47 -04:00
Follow the steps below to configure the GitHub service
hooks for your Automated Build:
2014-04-15 02:01:25 -04:00
< table class = "table table-bordered" >
< thead >
< tr >
< th > Step< / th >
< th > Screenshot< / th >
< th > Description< / th >
< / tr >
< / thead >
< tbody >
< tr >
< td > 1.< / td >
2014-07-09 19:43:39 -04:00
< td > < img src = "/docker-hub/hub-images/gh_settings.png" > < / td >
< td > Log in to Github.com, and go to your Repository page. Click on "Settings" on
the right side of the page. You must have admin privileges to the repository in order to do this.< / td >
2014-04-15 02:01:25 -04:00
< / tr >
< tr >
< td > 2.< / td >
2014-07-09 19:43:39 -04:00
< td > < img src = "/docker-hub/hub-images/gh_menu.png" alt = "Webhooks & Services" > < / td >
< td > Click on "Webhooks & Services" on the left side of the page.< / td > < / tr >
2014-07-10 19:51:16 -04:00
< tr > < td > 3.< / td >
< td > < img src = "/docker-hub/hub-images/gh_service_hook.png" alt = "Find the service labeled Docker" > < / td > < td > Find the service labeled "Docker" and click on it.< / td > < / tr >
2014-07-09 19:43:39 -04:00
< tr > < td > 4.< / td > < td > < img src = "/docker-hub/hub-images/gh_docker-service.png" alt = "Activate Service Hooks" > < / td >
2014-06-30 21:28:25 -04:00
< td > Make sure the "Active" checkbox is selected and click the "Update service" button to save your changes.< / td >
2014-04-15 02:01:25 -04:00
< / tr >
< / tbody >
< / table >
2014-06-30 21:28:25 -04:00
## Setting up Automated Builds with Bitbucket
2014-05-21 18:35:10 -04:00
2014-05-21 17:05:19 -04:00
In order to setup an Automated Build, you need to first link your
2014-08-09 07:55:47 -04:00
[Docker Hub ](https://hub.docker.com ) account with a Bitbucket account.
This will allow the registry to see your repositories.
2014-05-21 18:35:10 -04:00
2014-08-09 07:55:47 -04:00
To get started, log into your Docker Hub account and click the
"+ Add Repository" button at the upper right of the screen. Then
select [Automated Build ](https://registry.hub.docker.com/builds/add/ ).
2014-05-21 18:35:10 -04:00
2014-08-09 07:55:47 -04:00
Select the [Bitbucket source](
https://registry.hub.docker.com/associate/bitbucket/).
2014-05-21 18:35:10 -04:00
2014-08-09 07:55:47 -04:00
Then follow the onscreen instructions to authorize and link your
Bitbucket account to Docker Hub. Once it is linked, you'll be able
2015-02-03 23:17:56 -05:00
to choose a repository from which to create the Automatic Build.
2014-05-21 18:35:10 -04:00
2014-06-30 21:28:25 -04:00
### Creating an Automated Build
2014-05-21 18:35:10 -04:00
2014-06-08 19:03:46 -04:00
You can [create an Automated Build](
https://registry.hub.docker.com/builds/bitbucket/select/) from any of your
2014-06-30 21:28:25 -04:00
public or private Bitbucket repositories with a `Dockerfile` .
2014-05-21 18:35:10 -04:00
2014-07-10 19:51:16 -04:00
### Adding a Hook
2014-08-09 07:55:47 -04:00
When you link your Docker Hub account, a `POST` hook should get automatically
2015-02-03 23:17:56 -05:00
added to your Bitbucket repository. Follow the steps below to confirm or modify the
2014-08-09 07:55:47 -04:00
Bitbucket hooks for your Automated Build:
2014-07-10 19:51:16 -04:00
< table class = "table table-bordered" >
< thead >
< tr >
< th > Step< / th >
< th > Screenshot< / th >
< th > Description< / th >
< / tr >
< / thead >
< tbody >
< tr >
< td > 1.< / td >
< td > < img src = "/docker-hub/hub-images/bb_menu.png" alt = "Settings" width = "180" > < / td >
< td > Log in to Bitbucket.org and go to your Repository page. Click on "Settings" on
the far left side of the page, under "Navigation". You must have admin privileges
to the repository in order to do this.< / td >
< / tr >
< tr >
< td > 2.< / td >
< td > < img src = "/docker-hub/hub-images/bb_hooks.png" alt = "Hooks" width = "180" > < / td >
< td > Click on "Hooks" on the near left side of the page, under "Settings".< / td > < / tr >
< tr >
< td > 3.< / td >
< td > < img src = "/docker-hub/hub-images/bb_post-hook.png" alt = "Docker Post Hook" > < / td > < td > You should now see a list of hooks associated with the repo, including a < code > POST< / code > hook that points at
registry.hub.docker.com/hooks/bitbucket.< / td >
< / tr >
< / tbody >
< / table >
2014-06-30 21:28:25 -04:00
## The Dockerfile and Automated Builds
2014-04-15 02:01:25 -04:00
2014-08-09 07:55:47 -04:00
During the build process, Docker will copy the contents of your `Dockerfile` .
It will also add it to the [Docker Hub ](https://hub.docker.com ) for the Docker
2015-02-03 23:17:56 -05:00
community (for public repositories) or approved team members/orgs (for private
repositories) to see on the repository page.
2014-04-15 02:01:25 -04:00
2014-10-13 03:00:58 -04:00
### README.md
2014-04-15 02:01:25 -04:00
2014-06-30 21:28:25 -04:00
If you have a `README.md` file in your repository, it will be used as the
2014-07-09 19:43:39 -04:00
repository's full description.The build process will look for a
`README.md` in the same directory as your `Dockerfile` .
2014-04-15 02:01:25 -04:00
2014-04-18 16:21:55 -04:00
> **Warning:**
> If you change the full description after a build, it will be
2014-05-21 17:05:19 -04:00
> rewritten the next time the Automated Build has been built. To make changes,
2014-07-09 19:43:39 -04:00
> modify the `README.md` from the Git repository.
2014-04-15 02:01:25 -04:00
2014-12-04 22:05:38 -05:00
## Remote Build triggers
2014-04-15 02:01:25 -04:00
2014-08-09 07:55:47 -04:00
If you need a way to trigger Automated Builds outside of GitHub or Bitbucket,
you can set up a build trigger. When you turn on the build trigger for an
Automated Build, it will give you a URL to which you can send POST requests.
This will trigger the Automated Build, much as with a GitHub webhook.
2014-05-21 18:35:10 -04:00
2014-08-09 07:55:47 -04:00
Build triggers are available under the Settings menu of each Automated Build
2015-02-03 23:17:56 -05:00
repository on the Docker Hub.
2014-04-15 02:01:25 -04:00
2014-12-04 22:05:38 -05:00
![Build trigger screen ](/docker-hub/hub-images/build-trigger.png )
You can use `curl` to trigger a build:
```
$ curl --data "build=true" -X POST https://registry.hub.docker.com/u/svendowideit/testhook/trigger/be579c
82-7c0e-11e4-81c4-0242ac110020/
OK
```
2014-04-18 16:21:55 -04:00
> **Note:**
> You can only trigger one build at a time and no more than one
2014-07-09 19:43:39 -04:00
> every five minutes. If you already have a build pending, or if you
2014-04-15 02:01:25 -04:00
> recently submitted a build request, those requests *will be ignored*.
2014-08-09 07:55:47 -04:00
> To verify everything is working correctly, check the logs of last
> ten triggers on the settings page .
2014-04-15 02:01:25 -04:00
2014-12-04 22:05:38 -05:00
## Webhooks
2014-05-21 18:35:10 -04:00
2014-07-09 19:43:39 -04:00
Automated Builds also include a Webhooks feature. Webhooks can be called
2014-12-02 19:40:33 -05:00
after a successful repository push is made. This includes when a new tag is added
to an existing image.
2014-05-21 18:35:10 -04:00
2014-05-21 17:05:19 -04:00
The webhook call will generate a HTTP POST with the following JSON
2014-05-21 18:35:10 -04:00
payload:
```
{
2014-12-02 19:40:33 -05:00
"callback_url": "https://registry.hub.docker.com/u/svendowideit/testhook/hook/2141b5bi5i5b02bec211i4eeih0242eg11000a/",
"push_data": {
2015-02-03 23:17:56 -05:00
"images": [
"27d47432a69bca5f2700e4dff7de0388ed65f9d3fb1ec645e2bc24c223dc1cc3",
"51a9c7c1f8bb2fa19bcd09789a34e63f35abb80044bc10196e304f6634cc582c",
...
],
2014-12-02 19:40:33 -05:00
"pushed_at": 1.417566161e+09,
"pusher": "trustedbuilder"
},
"repository": {
"comment_count": 0,
"date_created": 1.417494799e+09,
"description": "",
"dockerfile": "#\n# BUILD\u0009\u0009docker build -t svendowideit/apt-cacher .\n# RUN\u0009\u0009docker run -d -p 3142:3142 -name apt-cacher-run apt-cacher\n#\n# and then you can run containers with:\n# \u0009\u0009docker run -t -i -rm -e http_proxy http://192.168.1.2:3142/ debian bash\n#\nFROM\u0009\u0009ubuntu\nMAINTAINER\u0009SvenDowideit@home.org.au\n\n\nVOLUME\u0009\u0009[\"/var/cache/apt-cacher-ng\"]\nRUN\u0009\u0009apt-get update ; apt-get install -yq apt-cacher-ng\n\nEXPOSE \u0009\u00093142\nCMD\u0009\u0009chmod 777 /var/cache/apt-cacher-ng ; /etc/init.d/apt-cacher-ng start ; tail -f /var/log/apt-cacher-ng/*\n",
"full_description": "Docker Hub based automated build from a GitHub repo",
"is_official": false,
"is_private": true,
"is_trusted": true,
"name": "testhook",
"namespace": "svendowideit",
"owner": "svendowideit",
"repo_name": "svendowideit/testhook",
"repo_url": "https://registry.hub.docker.com/u/svendowideit/testhook/",
"star_count": 0,
"status": "Active"
}
2014-05-21 18:35:10 -04:00
}
```
2014-12-02 19:40:33 -05:00
Webhooks are available under the Settings menu of each Repository.
2014-05-21 18:35:10 -04:00
2014-07-09 19:43:39 -04:00
> **Note:** If you want to test your webhook out we recommend using
2014-05-21 18:35:10 -04:00
> a tool like [requestb.in](http://requestb.in/).
2015-01-26 23:55:43 -05:00
> **Note**: The Docker Hub servers are currently in the IP range
> `162.242.195.64 - 162.242.195.127`, so you can restrict your webhooks to
> accept webhook requests from that set of IP addresses.
2014-12-02 19:40:33 -05:00
### Webhook chains
Webhook chains allow you to chain calls to multiple services. For example,
you can use this to trigger a deployment of your container only after
it has been successfully tested, then update a separate Changelog once the
deployment is complete.
After clicking the "Add webhook" button, simply add as many URLs as necessary
in your chain.
The first webhook in a chain will be called after a successful push. Subsequent
URLs will be contacted after the callback has been validated.
2014-12-04 22:05:38 -05:00
### Validating a callback
2014-12-02 19:40:33 -05:00
In order to validate a callback in a webhook chain, you need to
1. Retrieve the `callback_url` value in the request's JSON payload.
1. Send a POST request to this URL containing a valid JSON body.
> **Note**: A chain request will only be considered complete once the last
> callback has been validated.
To help you debug or simply view the results of your webhook(s),
view the "History" of the webhook available on its settings page.
2014-12-04 22:05:38 -05:00
### Callback JSON data
2014-12-02 19:40:33 -05:00
The following parameters are recognized in callback data:
* `state` (required): Accepted values are `success` , `failure` and `error` .
If the state isn't `success` , the webhook chain will be interrupted.
* `description` : A string containing miscellaneous information that will be
available on the Docker Hub. Maximum 255 characters.
* `context` : A string containing the context of the operation. Can be retrieved
from the Docker Hub. Maximum 100 characters.
* `target_url` : The URL where the results of the operation can be found. Can be
retrieved on the Docker Hub.
*Example callback payload:*
{
"state": "success",
"description": "387 tests PASSED",
"context": "Continuous integration by Acme CI",
"target_url": "http://ci.acme.com/results/afd339c1c3d27"
}
2014-05-21 18:35:10 -04:00
2014-12-04 22:05:38 -05:00
## Repository links
2014-04-15 02:01:25 -04:00
2014-08-09 07:55:47 -04:00
Repository links are a way to associate one Automated Build with
another. If one gets updated,the linking system triggers a rebuild
for the other Automated Build. This makes it easy to keep all your
Automated Builds up to date.
2014-04-15 02:01:25 -04:00
2015-02-03 23:17:56 -05:00
To add a link, go to the repository for the Automated Build you want to
2014-08-09 07:55:47 -04:00
link to and click on *Repository Links* under the Settings menu at
right. Then, enter the name of the repository that you want have linked.
2014-04-15 02:01:25 -04:00
2014-04-18 16:21:55 -04:00
> **Warning:**
> You can add more than one repository link, however, you should
2014-07-09 19:43:39 -04:00
> do so very carefully. Creating a two way relationship between Automated Builds will
> cause an endless build loop.