Why 'latest' tag is actually not latest in docker ?

Why 'latest' tag is actually not latest in docker ?

Problem Faced:

During feature development, we created a PR to be tested in DEV. The pipeline creates the image with my branch and push the image to the registry. Then it will be deploying the container to the DEV environment. But after successful deployment, i am not able to see my code changes. I tried re-deploying the image, but no use. My code changes aren't showing up in the dev environment.

Then i went through the build files (yaml files), then i saw they were tagging the image with 'latest' in docker build. The image with tag 'latest' also present in registry. Then why this problem ?

Reasons

After going through internet i found,

  1. The ’latest’ tag does not actually mean latest, it doesn’t mean anything. Its just a tag.

    Some people expect that :latest always points to the most-recently-pushed version of an image. That’s not true. 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:

    $ docker build -t company/image_name .

    $ docker build -t company/image_name:latest .

    Above two commands will produce the same output.

  2. Latest is Not Dynamic. So many people are not realizing that :latest is not dynamic. If you push a new image with a tag which is neither empty nor ’latest’, :latest will not be affected or created.

Solution

  1. Tag images with defined version number, like docker build -t company/image_name:1.0.0 .

  2. You should avoid using the :latest tag when deploying containers in production, because this makes it hard to track which version of the image is running and hard to roll back.

  3. If you’re working with an image which is tagged with “latest”, that’s all the information you have apart from the image ID. Operations like deploying a new version of your app, or rolling back are simply not possible, if you don’t have two distinctly tagged images which are stable.

Did you find this article valuable?

Support Parotta Salna by becoming a sponsor. Any amount is appreciated!