{"id":413949,"date":"2022-03-09T17:46:26","date_gmt":"2022-03-09T14:46:26","guid":{"rendered":"https:\/\/en.buradabiliyorum.com\/how-to-add-replace-and-remove-docker-image-tags-cloudsavvy-it\/"},"modified":"2022-03-09T17:46:26","modified_gmt":"2022-03-09T14:46:26","slug":"how-to-add-replace-and-remove-docker-image-tags-cloudsavvy-it","status":"publish","type":"post","link":"https:\/\/buradabiliyorum.com\/en\/how-to-add-replace-and-remove-docker-image-tags-cloudsavvy-it\/","title":{"rendered":"#How to Add, Replace, and Remove Docker Image Tags \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-6a2dc1889d6ff\" 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-6a2dc1889d6ff\" 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-1'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/buradabiliyorum.com\/en\/how-to-add-replace-and-remove-docker-image-tags-cloudsavvy-it\/#%E2%80%9CHow_to_Add_Replace_and_Remove_Docker_Image_Tags_%E2%80%93_CloudSavvy_IT%E2%80%9D\" >&#8220;How to Add, Replace, and Remove Docker Image Tags \u2013 CloudSavvy IT&#8221;<\/a><ul class='ez-toc-list-level-2' ><li class='ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/buradabiliyorum.com\/en\/how-to-add-replace-and-remove-docker-image-tags-cloudsavvy-it\/#Untagged_Images\" >Untagged Images<\/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\/how-to-add-replace-and-remove-docker-image-tags-cloudsavvy-it\/#Summary\" >Summary<\/a><\/li><\/ul><\/li><\/ul><\/nav><\/div>\n<h1><span class=\"ez-toc-section\" id=\"%E2%80%9CHow_to_Add_Replace_and_Remove_Docker_Image_Tags_%E2%80%93_CloudSavvy_IT%E2%80%9D\"><\/span>&#8220;How to Add, Replace, and Remove Docker Image Tags \u2013 CloudSavvy IT&#8221;<span class=\"ez-toc-section-end\"><\/span><\/h1>\n<div id=\"article-content-area\">\n<img loading=\"lazy\" decoding=\"async\" class=\"type:primaryImage aligncenter size-full wp-image-14169\" data-pagespeed-lazy-srcset=\"https:\/\/www.cloudsavvyit.com\/p\/uploads\/2021\/09\/993634a1.png?width=398&amp;trim=1,1&amp;bg-color=000&amp;pad=1,1 400w, https:\/\/www.cloudsavvyit.com\/p\/uploads\/2021\/09\/993634a1.png?width=1198&amp;trim=1,1&amp;bg-color=000&amp;pad=1,1 1200w\" sizes=\"auto, 400w, 1200w\" data-pagespeed-lazy-src=\"https:\/\/www.cloudsavvyit.com\/p\/uploads\/2021\/09\/993634a1.png?width=1198&amp;trim=1,1&amp;bg-color=000&amp;pad=1,1\" alt=\"\" width=\"1200\" height=\"675\" src=\"\/pagespeed_static\/1.JiBnMqyl6S.gif\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<p>Docker uses tags to identify distinct versions of an image. In common with the broader container community, tags should be used to mark each release so users can select between different versions.<\/p>\n<p>Tags may also be used to describe other characteristics of an image such as the identity of a key dependency when multiple options are offered. It\u2019s not uncommon to find image vendors offering this kind of tag:<\/p>\n<pre>example-image:1.1.0-apache&#13;\nexample-image:1.1.0-nginx&#13;\nexample-image:1.2.0-apache&#13;\nexample-image:1.2.0-nginx<\/pre>\n<p>This tag scheme lets you pick between different versions of the image while offering either Apache or NGINX as the image\u2019s base.<\/p>\n<p>You can add your own tags to any image you build or pull. Local tags give you a way to quickly identify specific images in the future. In this guide, we\u2019ll show how to manage image tags with the Docker CLI.<\/p>\n<p>Tags are added to images using the <a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/docs.docker.com\/engine\/reference\/commandline\/tag\"><code>docker tag<\/code><\/a> command. Tags can also be attached when you\u2019re building an image with <a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/docs.docker.com\/engine\/reference\/commandline\/build\"><code>docker build<\/code><\/a> by passing the <code>-t<\/code> flag.<\/p>\n<p>The <code>tag<\/code> command takes two arguments: an <em>existing<\/em> tag identifying an image and a new \u201ctarget\u201d tag to assign to that image:<\/p>\n<pre># docker tag &lt;source image&gt; &lt;new tag&gt;&#13;\ndocker tag example-image:1.1.0 example-image:1.1.0-apache<\/pre>\n<p>Both tags will now refer to the same image so you can start to use them interchangeably. However, running <code>docker pull example-image:1.1.0<\/code> would not affect the <code>1.1.0-apache<\/code> tag. A tag\u2019s image reference isn\u2019t updated unless you\u2019ve manually included it in a CLI command.<\/p>\n<p>The one exception to this rule is the often misunderstood <code>latest<\/code> tag. When you pull a \u201cbare\u201d image without a tag, such as <code>docker pull example-image<\/code>, Docker implicitly uses <code>latest<\/code>.<\/p>\n<h2 id=\"untagged-images\"><span class=\"ez-toc-section\" id=\"Untagged_Images\"><\/span>Untagged Images<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>The <code>docker tag<\/code> command will accept image IDs as the source reference instead of an existing tag. If you end up with an untagged image, run the <code>docker images<\/code> command to find its ID, then use <code>docker tag<\/code> to assign a new tag:<\/p>\n<pre>docker tag 0e3e06b48755 example-image:latest<\/pre>\n<p>It\u2019s possible to have untagged images when you pull a new version of a tag:<\/p>\n<pre># already has example-image:latest&#13;\ndocker pull example-image:latest<\/pre>\n<p>The original target of the <code>example-image:latest<\/code> tag still exists on your system but is now untagged. The pull <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\">download<\/a>ed the new image data and reassigned the <code>latest<\/code> tag to reference it.<\/p>\n<p>One situation where you need to add a new tag is when you\u2019re pushing images between registries. The registry URL is part of the tag. Add a new tag that includes the registry you want to push to, then use <code>docker push<\/code> to upload it:<\/p>\n<pre>docker tag example-image:latest registry.example.com\/example-image:latest&#13;\ndocker push registry.example.com\/example-image:latest<\/pre>\n<p>Pushing a bare tag without a URL component will send the image data to Docker Hub. Consequently you must add a tag with your server\u2019s hostname and optional port number when you\u2019re interacting with a private registry.<\/p>\n<p>The <code>docker tag<\/code> command will silently replace a tag\u2019s reference if an existing tag is used as the target:<\/p>\n<pre>docker tag first-image:latest demo&#13;\ndocker tag second-image:latest demo<\/pre>\n<p>The <code>demo<\/code> tag now refers to <code>second-image<\/code> and cannot be used to reference <code>first-image<\/code>. You can still interact with the first image using its remaining tag, <code>first-image:latest<\/code>. The second image can be selected with either <code>second-image:latest<\/code> or <code>demo<\/code>.<\/p>\n<p>Image tags should <a href=\"https:\/\/buradabiliyorum.com\/en\/category\/general\/\" data-internallinksmanager029f6b8e52c=\"3\" title=\"General\" target=\"_blank\" rel=\"noopener\">general<\/a>ly be treated as immutable. This technique of modifying a tag\u2019s reference is best avoided except for tags you\u2019re using for local organizational purposes. It\u2019s not a good idea to push an updated tag to a public registry as users depending on it will receive an unexpectedly modified image next time they pull. Push another new tag instead in this situation.<\/p>\n<pre># Build and push v1&#13;\ndocker build -t example-image:v1 .&#13;\ndocker push example-image:v1&#13;\n&#13;\n# v1 now refers to different image data&#13;\n# This is fine for local use (tags in the &#13;\n# registry are independent of your local tags).&#13;\ndocker build -t example-image:v1 .&#13;\n&#13;\n# Don't do this - now the tag in the registry&#13;\n# has been changed too, which could negatively &#13;\n# impact existing users.&#13;\ndocker push example-image:v1<\/pre>\n<p>You can remove tags from images that you\u2019ve pulled to your machine. Use the <code>docker rmi<\/code> command, specifying the tag you\u2019d like to delete:<\/p>\n<pre>docker rmi example-image:1.1.0-apache<\/pre>\n<p>Any other tags referencing the same image data will remain usable. In the event the referenced image would become untagged, the Docker CLI deletes the image data altogether. This ensures you don\u2019t end up with untagged images as a result of explicit removal instructions.<\/p>\n<p>Removing a tag only has an effect locally, even if you\u2019re referencing a tag that includes a registry URL:<\/p>\n<pre># Does not remove the tag from the registry!&#13;\ndocker rmi registry.example.com\/example-image:latest<\/pre>\n<p>You can\u2019t currently delete a specific tag from a registry. This is in keeping with the principle of tag immutability: once you\u2019ve pushed content, it could be used as a dependency by downstream consumers, so the <a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/docs.docker.com\/registry\/spec\/api\/#deleting-an-image\">Registry API<\/a> omits a tag deletion endpoint. However many third-party registry implementations do provide an equivalent mechanism; it\u2019s worth checking the documentation for yours if you have a compelling reason to delete a pushed tag.<\/p>\n<h2 id=\"summary\"><span class=\"ez-toc-section\" id=\"Summary\"><\/span>Summary<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Tags are used to label Docker images with key distinguishing information such as their build version and included dependencies. Tags are much simpler to work with than the image SHA IDs which you can view with <code>docker images<\/code>. Tags are also the primary mechanism for interacting with images in remote registries.<\/p>\n<p>You can manage your own tags on your local machine but changes will not affect registry content. You should also consider that although tags <em>are<\/em> mutable, this property should not be abused and is best avoided when pushing tags to a registry. This helps protect your users from unwanted breaking changes.\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\/15422\/how-to-add-replace-and-remove-docker-image-tags\/\" target=\"_blank\" rel=\"noopener\">Source<\/a><\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>&#8220;How to Add, Replace, and Remove Docker Image Tags \u2013 CloudSavvy IT&#8221; Docker uses tags to identify distinct versions of an image. In common with the broader container community, tags should be used to mark each release so users can select between different versions. Tags may also be used to describe other characteristics of an&#8230;<\/p>\n","protected":false},"author":1,"featured_media":413950,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"fifu_image_url":"https:\/\/www.cloudsavvyit.com\/p\/uploads\/2021\/09\/993634a1.png","fifu_image_alt":"","footnotes":""},"categories":[18],"tags":[],"class_list":["post-413949","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\/413949","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=413949"}],"version-history":[{"count":0,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/posts\/413949\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/media\/413950"}],"wp:attachment":[{"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/media?parent=413949"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/categories?post=413949"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/tags?post=413949"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}