Tagging Docker image (SemVer)

3/7/2019

i need small help. What is the best option for tagging docker images. I am looking to make bash script. Is that recommended or is there any different solution? I would like to add a way to tag my docker images generated by the jenkins build step. I need to auto-increment the BuildNumber, but to manually set the MajorVersion and MinorVersion.

I can't find any example related to this. Could you provide me any example to manage my version numbers.

-- Mirke
docker
dockerfile
kubernetes

1 Answer

3/7/2019

In my experience, it's not a very good practice to tag your images with build numbers as part of your image "version". As stated in SemVer, the third part of the version number is the "Patch", representing a non-breaking fix.

The problem with just adding a build number as the patch version is that you aren't necessarily representing a patch with every build. For example, imagine you're working on a fix (which will get released as a patch version). But you don't nail that fix correctly on your first commit/push to your working branch. That first build will already be a build-number increment, as will any other pushes from other devs to other branches. And this will all depend on how your CI is set up.

If you need to put the build number, then you can use your CI build number (I think all CI solutions provide that) and add them to your tag as a fourth element in the semver (e.g.: 2.4.1-2312, where 2312 is the build number), and once it gets released you can bump the tag to 2.4.2.

If you want to be compliant with the docker usual practices, you should also tag 2.4.2 as 2.4, 2 and latest, if you're to release it.

My last advise would be to always tag an image with the full SHA of the commit you're building, as there's no easier way for matching an image to a point in time in your codebase.

-- gvilarino
Source: StackOverflow