{"id":241698,"date":"2021-05-04T15:00:15","date_gmt":"2021-05-04T12:00:15","guid":{"rendered":"https:\/\/en.buradabiliyorum.com\/understanding-dockers-latest-tag-cloudsavvy-it\/"},"modified":"2021-05-04T15:00:15","modified_gmt":"2021-05-04T12:00:15","slug":"understanding-dockers-latest-tag-cloudsavvy-it","status":"publish","type":"post","link":"https:\/\/buradabiliyorum.com\/en\/understanding-dockers-latest-tag-cloudsavvy-it\/","title":{"rendered":"#Understanding Docker\u2019s \u201clatest\u201d Tag \u2013 CloudSavvy IT"},"content":{"rendered":"<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_84 counter-hierarchy ez-toc-counter ez-toc-custom ez-toc-container-direction\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<label for=\"ez-toc-cssicon-toggle-item-6a2496ac11608\" class=\"ez-toc-cssicon-toggle-label\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #dd3333;color:#dd3333\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #dd3333;color:#dd3333\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/label><input type=\"checkbox\"  id=\"ez-toc-cssicon-toggle-item-6a2496ac11608\" checked aria-label=\"Toggle\" \/><nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/buradabiliyorum.com\/en\/understanding-dockers-latest-tag-cloudsavvy-it\/#The_Problems_With_latest\" >The Problems With latest<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/buradabiliyorum.com\/en\/understanding-dockers-latest-tag-cloudsavvy-it\/#Avoid_Pinning_to_latest\" >Avoid Pinning to latest<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/buradabiliyorum.com\/en\/understanding-dockers-latest-tag-cloudsavvy-it\/#Immutability\" >Immutability<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/buradabiliyorum.com\/en\/understanding-dockers-latest-tag-cloudsavvy-it\/#Better_Approaches_to_Tagging\" >Better Approaches to Tagging<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/buradabiliyorum.com\/en\/understanding-dockers-latest-tag-cloudsavvy-it\/#Summary\" >Summary<\/a><\/li><\/ul><\/nav><\/div>\n<p><strong>&#8220;#Understanding Docker\u2019s \u201clatest\u201d Tag \u2013 CloudSavvy IT&#8221;<\/strong><\/p>\n<div id=\"article-content-area\">\n<img loading=\"lazy\" decoding=\"async\" class=\"type:primaryImage aligncenter size-full wp-image-9034\" data-pagespeed-lazy-src=\"https:\/\/www.cloudsavvyit.com\/p\/uploads\/2021\/01\/6dc7b5a0.jpeg?width=1200&amp;trim=1,1&amp;bg-color=000&amp;pad=1,1\" alt=\"\" width=\"1602\" height=\"902\" src=\"\/pagespeed_static\/1.JiBnMqyl6S.gif\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<p>Docker tags are used to identify images by name. Each image can have multiple tags assigned. Tags look similar to <code>my-image:latest<\/code>, with the part before the colon defining the image name and the latter section specifying the version.<\/p>\n<p>You can tag an image without anything after the colon. Your image will be automatically given <code>latest<\/code> as its version tag. This is a common source of confusion for newcomers to Docker.<\/p>\n<h2 id=\"the-problems-with-latest\"><span class=\"ez-toc-section\" id=\"The_Problems_With_latest\"><\/span>The Problems With latest<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>The semantics of the <code>latest<\/code> tag <em>seem<\/em> to suggest some special meaning beyond what actually exists. In reality, <code>latest<\/code> is used as the default tag when you haven\u2019t specified anything else. That\u2019s the <em>only<\/em> time it\u2019ll be used \u2013 it doesn\u2019t automatically refer to the <em>newest<\/em> image you\u2019ve built.<\/p>\n<p>Here\u2019s an example of the resulting problem:<\/p>\n<pre># Creates my-image:latest (first image)&#13;\ndocker build -t my-image&#13;\n&#13;\n# Updates my-image:latest (second image)&#13;\ndocker build -t my-image:latest&#13;\n&#13;\n# Creates my-image:v1 (third image)&#13;\ndocker build -t my-image:v1<\/pre>\n<p>If you now ran <code>docker run my-image:latest<\/code>, you\u2019d be using the <em>second<\/em> image to be built. The <code>v1<\/code> tag is completely independent of <code>latest<\/code>, so building the third image has no effect on the existing two. If you wanted <code>my-image:v1<\/code> to also become the <code>latest<\/code> image, you\u2019d need to manually tag and push it in a separate operation.<\/p>\n<p>This creates a lot of confusion within the Docker ecosystem. Many image creators <em>do<\/em> tag their newest releases with <code>latest<\/code>. This imbues the tag with extra importance that Docker didn\u2019t intend. Other authors use <code>latest<\/code> for their development builds, while some won\u2019t publish a <code>latest<\/code> tag at all.<\/p>\n<p>The lack of consistency among image authors can make it unclear whether <code>latest<\/code> is <em>really<\/em> the latest image or not. The most important rule of <code>latest<\/code> is to never make assumptions about how a particular image will use the tag.<\/p>\n<h2 id=\"avoid-pinning-to-latest\"><span class=\"ez-toc-section\" id=\"Avoid_Pinning_to_latest\"><\/span>Avoid Pinning to latest<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>You shouldn\u2019t consume the <code>latest<\/code> tag of an image whenever a more specific alternative is available. Unless you <em>know<\/em> the image\u2019s author actively updates the <code>latest<\/code> tag, pinning against it might not deliver the version you expect.<\/p>\n<p>Most images use semantic versioning to create release tags. It\u2019s much safer to consume <code>my-image:1.1<\/code> than <code>my-image:latest<\/code>. If the author doesn\u2019t maintain <code>latest<\/code>, you could end up with a heavily outdated image. Conversely, authors that <em>do<\/em> maintain <code>latest<\/code> often use the tag for their bleeding-edge development version. Pinning against it is likely to deliver regular breaking changes that you won\u2019t be warned about.<\/p>\n<p>Several container ecosystem projects now warn against using <code>latest<\/code> for this reason. Kubernetes <a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/kubernetes.io\/docs\/concepts\/configuration\/overview\/#container-images\">notes that<\/a> using <code>latest<\/code> is not only unpredictable but also makes it harder for you to identify the <em>real<\/em> image version used by your containers.<\/p>\n<p>Rolling back a container that\u2019s deployed with <code>latest<\/code> isn\u2019t directly possible. You\u2019ve got no reference point to work with. Changing an image tag from <code>1.1.0<\/code> to <code>2.1.0<\/code> lets you easily revert the upgrade if you need to. Container orchestration tools can\u2019t help you change \u201cthe new <code>latest<\/code> image\u201d back into \u201cthe old <code>latest<\/code> image\u201d.<\/p>\n<h2 id=\"immutability\"><span class=\"ez-toc-section\" id=\"Immutability\"><\/span>Immutability<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>More fundamentally, good tagging practice dictates that image tags should be immutable. Once a tag\u2019s been assigned, that tag shouldn\u2019t be reused by the same image. This allows downstream consumers to pin against specific versions, safe in the knowledge they\u2019ll get the same image each time.<\/p>\n<p><code>latest<\/code> breaks this system by being inherently mutable. If you use <code>latest<\/code>, you have to accept change. As an image author, you\u2019ll make it more difficult for users to confidently reference your image if you only publish with the <code>latest<\/code> tag.<\/p>\n<p>Many tools make assumptions about how image tags are used. <code>latest<\/code> often gets special treatment which you need to stay aware of. Kubernetes, for example, will <em>always<\/em> <a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/kubernetes.io\/docs\/concepts\/containers\/images\">try to pull<\/a> a newer version of the <code>latest<\/code> tag, even if one already exists locally. Other tags only get pulled if they don\u2019t already exist within the cluster.<\/p>\n<h2 id=\"better-approaches-to-tagging\"><span class=\"ez-toc-section\" id=\"Better_Approaches_to_Tagging\"><\/span>Better Approaches to Tagging<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Try to stick to semantic versioning when you\u2019re tagging images that will be publicly available. This is a widely understood standard that helps communicate the magnitude of each change you make to your image.<\/p>\n<p>You have more options when creating images for private use. Images which are built by a CI server can often be tagged with the SHA of the commit which ran the pipeline. This ensures each pipeline creates a unique tag that won\u2019t be overwritten in the future. It also helps you match images in your container registry to the codebase changes that created them.<\/p>\n<p>Finally, don\u2019t overthink the <code>latest<\/code> tag. You don\u2019t need to keep it updated with the \u201clatest\u201d version of your image. It\u2019s often best to ignore it altogether \u2013 unless you run <code>docker build<\/code> without a tag name, it\u2019ll never be created. If you do publish a <code>latest<\/code> tag, make sure you state what it will refer to.<\/p>\n<h2 id=\"summary\"><span class=\"ez-toc-section\" id=\"Summary\"><\/span>Summary<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>The <a href=\"https:\/\/buradabiliyorum.com\/en\/category\/download-scripts-themes-apps\/\" data-internallinksmanager029f6b8e52c=\"9\" title=\"Download Scripts &amp; Themes &amp; Apps\" target=\"_blank\" rel=\"noopener\">app<\/a>arent simplicity of Docker\u2019s <code>latest<\/code> tag masks a quagmire of possible issues. You\u2019ll encounter them both as an image author and consumer. The problems stem from the semantic inconsistency of the tag: while it sounds dynamic, it\u2019s nothing more than a static tag assigned by Docker in the absence of a user-supplied value.<\/p>\n<p>You should pin against specific image versions wherever possible. This will help you avoid breaking changes and ambiguous third-party tool behaviours. As an image author, try to provide semantic release versions and make it clear how your project treats <code>latest<\/code>. This will help prospective users assess how to reference your image.\n<\/div>\n<blockquote><p><strong><span style=\"color: #ff6600;\">If you liked the article, do not forget to share it with your friends. Follow us on\u00a0<span style=\"color: #ff0000;\"><a style=\"color: #ff0000;\" href=\"https:\/\/news.google.com\/publications\/CAAqBwgKMLG0nwswvr63Aw\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">Google News<\/a><\/span>\u00a0too, click on the star and choose us from your favorites.<\/span><\/strong><\/p><\/blockquote>\n<blockquote>\n<p style=\"text-align: center;\">For forums sites go to <span style=\"color: #ff9900;\"><a style=\"color: #ff9900;\" href=\"https:\/\/forum.buradabiliyorum.com\/\" target=\"_blank\" rel=\"noopener\">Forum.BuradaBiliyorum.Com<\/a><\/span><\/strong><\/p>\n<\/blockquote>\n<blockquote>\n<p style=\"text-align: center;\"><strong>If you want to read more like this article, you can visit our <span style=\"color: #ff9900;\"><a style=\"color: #ff9900;\" href=\"https:\/\/en.buradabiliyorum.com\/technology\/\" target=\"_blank\" rel=\"noopener\">Technology category.<\/a><\/span><\/strong><\/p>\n<\/blockquote>\n<p><span style=\"color: black;\"><a style=\"color: #ff9900;\" href=\"https:\/\/www.cloudsavvyit.com\/10691\/understanding-dockers-latest-tag\/\" target=\"_blank\" rel=\"noopener\">Source<\/a><\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>&#8220;#Understanding Docker\u2019s \u201clatest\u201d Tag \u2013 CloudSavvy IT&#8221; Docker tags are used to identify images by name. Each image can have multiple tags assigned. Tags look similar to my-image:latest, with the part before the colon defining the image name and the latter section specifying the version. You can tag an image without anything after the colon&#8230;.<\/p>\n","protected":false},"author":1,"featured_media":241699,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"fifu_image_url":"https:\/\/www.cloudsavvyit.com\/p\/uploads\/2021\/01\/6dc7b5a0.jpeg","fifu_image_alt":"","footnotes":""},"categories":[18],"tags":[],"class_list":["post-241698","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-technology"],"_links":{"self":[{"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/posts\/241698","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/comments?post=241698"}],"version-history":[{"count":0,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/posts\/241698\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/media\/241699"}],"wp:attachment":[{"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/media?parent=241698"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/categories?post=241698"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/tags?post=241698"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}