Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to increment docker tag automatically?

I am planning to increment docker tag automatically using shell script. Right now i am using Date function to insert %m%d%y%H%M for docker tag. Every time, current month year and date with Hours and mins are inserting like 03262016091.

But when I see it in Docker hub, it's not looking good and planning to keep the version names as 1.0.0 or with git commit number.

I am using Travis CI for my continuous Integration but not to build docker images. I have shell script to do that using Docker file.

My Requirement is:

I have to increment below version number everytime when I execute my build.

Version=1.0.0

Could you please help me how to do this?

like image 572
rameshthoomu Avatar asked Mar 26 '16 13:03

rameshthoomu


People also ask

Does Docker automatically tag latest?

In reality, latest is used as the default tag when you haven't specified anything else. That's the only time it'll be used – it doesn't automatically refer to the newest image you've built. If you now ran docker run my-image:latest , you'd be using the second image to be built.

Can a Docker image have more than one tag?

In Docker, we can also assign multiple tags to an image. Here, we'll use the docker build command to assign multiple tags to an image in a single command.

How do I tag a Docker image as latest?

Latest is Just a Tag It's just the tag which is applied to an image by default which does not have a tag. Those two commands will both result in a new image being created and tagged as :latest: # those two are the same: $ docker build -t company/image_name . $ docker build -t company/image_name:latest .


2 Answers

You could use the git revision which is unique as well. Most simple solution from the command line is a nested git-rev command:

docker tag <image> <image>:$(git rev-parse --short HEAD)"

gives you e.g.

<image> = myImage >> myImage:67df348
like image 161
Flowkap Avatar answered Sep 24 '22 12:09

Flowkap


If your repository were named your/project and was tagged with 1.0, then following should rebuild it with tag 1.01:

docker build -t your/project:$(docker images | awk '($1 == "your/project") {print $2 += .01; exit}') .
like image 23
Cole Tierney Avatar answered Sep 24 '22 12:09

Cole Tierney