44

When specifying an Automated Build on Docker Hub, I can set some settings (Type ('Branch' or 'Tag'), Name, Dockerfile Location and Docker Tag Name). But unfortunately I didn't find any documentation for those.

I assume, that when I choose Type 'Branch' and enter a Name, this is the branch from my git repository on GitHub/BitBucket being used and that Docker Tag Name results in the tag being assigned to the created image.

I played around a bit with it and found some things that are not clear to me - but I hope you can explain to me.

  • adding more than one entry results in only one tag being assigned. I used 'Branch', 'master' and '/' and 'latest' as the Docker Tag Name in the first one, 'v1' in the second one. But only 'v1' is used as a tag.

  • Using Type 'Tag' didn't result in different result. I thought this might only build an image if a git commit is tagged with this value. What is this type for?

I was looking for the ability to assign the tag 'latest' to the latest build and use a scheme like v1, v2, v3 and so on for older builds as I could do when building images locally.

Chris Martin
  • 30,334
  • 10
  • 78
  • 137
MirkoMachine
  • 501
  • 1
  • 5
  • 6
  • Check this forum entry related to your question, it hasn't been answered yet (at the time of this comment): https://forums.docker.com/t/automated-builds-not-tagging-latest/683 – Joaquin Sargiotto Jan 26 '15 at 13:56

7 Answers7

52

Automated docker image tagging is available on dockerhub! I fiddled with this recently and wanted to share my findings, jumping on this thread (hope it's ok!)

So I have a public GitHub repo with an automated build link on dockerhub. I want the :latest tag to be updated every time I push to the master branch. Also, I want :X, :X.Y and :X.Y.Z tags to be created for every release I create on GitHub (tagged as vX.Y.Z on GitHub).

Here is how the build settings config looks like to support this: dockerhub build settings

And in text so it's easier to copy-paste:

| Type   | Name                              | Dockerfile Location | Docker Tag Name |
|--------|-----------------------------------|---------------------|-----------------|
| Branch | master                            | /                   | latest          |
| Tag    | /^v([0-9]+)\.([0-9]+)\.([0-9]+)$/ | /                   | {\1}            |
| Tag    | /^v([0-9]+)\.([0-9]+)\.([0-9]+)$/ | /                   | {\1}.{\2}       |
| Tag    | /^v([0-9]+)\.([0-9]+)\.([0-9]+)$/ | /                   | {\1}.{\2}.{\3}  |

Hope this helps!

Anton Drukh
  • 873
  • 7
  • 12
17

This is VERY EASY in 2 STEPS ...

STEP 1 - Click the Automated Build link

Automated build link

STEP 2 - Add multiple automated builds to the same docker repo (most people do not know you can add multiple automated builds) by clicking the BLUE PLUS BUTTON (see image below)

Adding multiple automated builds

In the example in the image above I am ...

  • adding a "latest" docker tag which maps to the github master branch
  • adding a "0.1.0" docker tag which maps to the github 0.1.0 tag

Note that the github tag must exist!

NOW when I click save and trigger build 2 builds are started, one for the latest tag and one for the 0.1.0 tag.

Simple when you know how :) Thought I'd provide a full answer here since this is poorly documented.

danday74
  • 52,471
  • 49
  • 232
  • 283
  • 3
    It would be nice to be able to tell dockerhub to create a new image with the same tag as in git whenever a new tag is pushed to the repo. – Reto Gmür Oct 30 '15 at 14:05
  • agreed, i dont think this is possible sadly – danday74 Nov 03 '15 at 08:25
  • What if 0.1.0 is just a tag on the tip of master? Is there any way to teach Docker Hub to only build one image but give it both the `0.1.0` and `latest` tags? Asked similar/same question here: https://stackoverflow.com/questions/37650119/how-do-i-make-a-docker-hub-use-the-same-image-for-latest-and-vx-x – Adam Monsen Jun 08 '16 at 05:05
  • 1
    I dont think this nomenclature qualifies as "Automated Build" if I have to come in and match tags and trigger the process manually. For that matter I can write an actual script which will automate this on my dev workstation. – Michael M Sep 22 '16 at 20:33
  • 1
    I think that's how version tagging should be. I.e. a manual process. The automated build will mark things as :latest, always. However, if what you want is to automatically match version tags between github and dockerhub, then you can use a regex for the tag. E.g. `/^v[0-9.]+$/`, and it will automatically make those for you, matching that in the github repo. Perhaps best of both worlds? – swalog Jul 17 '18 at 14:04
7

For the new Docker Hub Automated Build Anton Drukh's excellent answer can be achieved with a single rule

Source Type: Tag

Source: /^v([0-9.])\.([0-9.])\.([0-9.])$/

Docker Tag: release-{\1},release-{\1}.{\2},release-{\1}.{\2}.{\3},latest

Note that this is slightly different from Anton's answer as I am building latest from tag rather than master commit.

froblesmartin
  • 1,527
  • 18
  • 25
Michael West
  • 1,636
  • 16
  • 23
  • 2
    I would recommend using '+' instead or '.' as we want to be sure that there is a number always for each version level. – froblesmartin Apr 11 '19 at 10:37
  • to second froblesmartin's comment; the git tag `vi.l.e` will produce docker tags `release-i`, `release-i.l`, and `release-i.l.e`. You SHOULD (RFC2119) use semver.org versioning. The source should be: `/^v([0-9+])\.([0-9+])\.([0-9+])$/` to avoid any issues with invalid semver tags. – jnovack Jun 17 '20 at 12:43
4

A few months ago I contacted docker support about explicitly providing version numbers and that was not supported at the time.

What you specify on the docker hub is the git tag/branch that will be watched. The result of the build will always be tagged latest.

Abel Muiño
  • 7,611
  • 3
  • 24
  • 15
  • do u have a link for this in https://forums.docker.com/ , it will be good to have a reference, I prefer this feature as well. – Larry Cai Jan 08 '15 at 01:22
  • Unfortunately, this was handled via support.docker.com which I don't think allows public links (it's running zendesk). It is request 54 if that helps. On April 1st 2014 it was closed because "we have some changes that we are working on, that should be available in the near future that might handle your situation" so there might have been improvements since then. – Abel Muiño Jan 09 '15 at 20:47
4

Usman answered with a workaround for a similar question in https://stackoverflow.com/a/26107743/155689

Basically

  • go into the automated build settings,
  • add another build type using tag
  • enter a git tag name
  • and give it a version name
  • click save and trigger build

As you can see I have done this for this automated build

Community
  • 1
  • 1
flurdy
  • 3,782
  • 29
  • 31
3

My solution to assign the tag "latest" to the latest build is to use the following configuration in the automated build:

| Type   | Name   | Dockerfile Location | Tag Name |
| Branch | master |        /            | latest   |

Whenever there is a commit in master, a new build with tag "latest" is created.

There was a problem a few days ago, where the automated build used the branch name as the tag name, so you might found a couple of builds with the "master". This is fixed: https://forums.docker.com/t/automated-builds-not-tagging-latest/683

Joaquin Sargiotto
  • 1,646
  • 13
  • 12
1

I haven't used this feature yet so I can be wrong, but today when I went to the build settings tab and selected tag for the second type of build, it automatically had the regex /.*/ which will select all tags.

I'll update this as soon as I test it.

hernandes
  • 371
  • 1
  • 5
  • 14