{"id":301504,"date":"2021-07-16T14:30:00","date_gmt":"2021-07-16T11:30:00","guid":{"rendered":"https:\/\/en.buradabiliyorum.com\/how-do-docker-tags-work-cloudsavvy-it\/"},"modified":"2021-07-16T14:30:00","modified_gmt":"2021-07-16T11:30:00","slug":"how-do-docker-tags-work-cloudsavvy-it","status":"publish","type":"post","link":"https:\/\/buradabiliyorum.com\/en\/how-do-docker-tags-work-cloudsavvy-it\/","title":{"rendered":"#How Do Docker Tags Work? \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-6a2d8c773a0bb\" 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-6a2d8c773a0bb\" 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\/how-do-docker-tags-work-cloudsavvy-it\/#Container_vs_Image\" >Container vs. Image<\/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\/how-do-docker-tags-work-cloudsavvy-it\/#Tags_Track_Versions_of_Built_Images\" >Tags Track Versions of Built 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-do-docker-tags-work-cloudsavvy-it\/#Latest_Doesnt_Always_Mean_%E2%80%9CLatest%E2%80%9D\" >Latest Doesn\u2019t Always Mean \u201cLatest\u201d<\/a><\/li><\/ul><\/nav><\/div>\n<p><strong>&#8220;#How Do Docker Tags Work? \u2013 CloudSavvy IT&#8221;<\/strong><\/p>\n<div id=\"article-content-area\">\n<img loading=\"lazy\" decoding=\"async\" class=\"type:primaryImage imgchk9 alignnone wp-image-503 size-full\" srcset=\"https:\/\/www.cloudsavvyit.com\/p\/uploads\/2019\/06\/c454d054.png?width=398&amp;trim=1,1&amp;bg-color=000&amp;pad=1,1 400w, https:\/\/www.cloudsavvyit.com\/p\/uploads\/2019\/06\/c454d054.png?width=1198&amp;trim=1,1&amp;bg-color=000&amp;pad=1,1 1200w\" sizes=\"auto, 400w, 1200w\" src=\"https:\/\/www.cloudsavvyit.com\/p\/uploads\/2019\/06\/c454d054.png?width=398&amp;trim=1,1&amp;bg-color=000&amp;pad=1,1\" alt=\"Docker logo.\" width=\"700\" height=\"300\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<p>Docker images use registries for version control, such as the Docker Hub that hosts public images for anyone to <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> and run. However, before uploading an image to the Hub or any registry, you must give it the proper tags.<\/p>\n<h2 role=\"heading\" aria-level=\"2\"><span class=\"ez-toc-section\" id=\"Container_vs_Image\"><\/span>Container vs. Image<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>It\u2019s important to understand the difference between containers and images before talking about tags, as they\u2019re often used fairly interchangeably and that can lead to some confusion.<\/p>\n<p>A Docker image is what you get from running <code>docker build<\/code>\u00a0with your Dockerfile. It\u2019s made up of multiple layers to optimize disk and memory usage. An image is a read-only.<\/p>\n<p>A Docker container is an instance of an image that the processes actually run in. It\u2019s a read\/write file system, so\u00a0essentially, an image is a template that you use to create multiple containers from. It contains the base code and everything the app needs to get started. The containers get initialized with the image when created, then it can modify the file system as they please.<\/p>\n<p>Images are what you push to the container registry. Then, on your servers, you can reference the image in the registry to download the container.<\/p>\n<h2 role=\"heading\" aria-level=\"2\"><span class=\"ez-toc-section\" id=\"Tags_Track_Versions_of_Built_Images\"><\/span>Tags Track Versions of Built Images<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Whenever you run a <code>docker build<\/code>, you create a new image with a unique ID, like \u201c38054d5e8a27.\u201d<\/p>\n<p>Tags are simply labels that provide a better way to manage version control and releases. They\u2019re like labels that you can assign to any completed build. Rather than referencing the build ID, you can tag an image with a label in the major.minor.patch format and easily be able to tell which image is which, or whatever format your organization prefers.<\/p>\n<p>Tagging is pretty easy. You can use <code>docker tag<\/code>\u00a0to do it after the fact, but it\u2019s much easier to do it when you build using the <code>-t<\/code>\u00a0flag:<\/p>\n<pre> docker build -t repository\/image:tag .<\/pre>\n<p>This builds the image from the Dockerfile and tags it with the tag you specified. The tag is the <code>[:TAG]<\/code>\u00a0part, after the semicolon, even though Docker will say \u201c<code>Successfully tagged repository\/image:tag<\/code>.\u201d The <code>repository\/image<\/code>\u00a0part is just the name of the image, and if you\u2019re planning on pushing to a repository, you must tag it in the <code>repository\/image:tag<\/code>\u00a0format.<\/p>\n<p>For Docker Hub, the repository name is just your username, so the command would look something like:<\/p>\n<pre> docker build -t anthonyheddings\/nginx:tag .<\/pre>\n<p>If you don\u2019t specify a specific tag, Docker automatically tags it as \u201clatest.\u201d<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-5636 imgchk9\" src=\"https:\/\/www.cloudsavvyit.com\/p\/uploads\/2020\/07\/ec02c4ef.png?trim=1,1&amp;bg-color=000&amp;pad=1,1\" alt=\"\" width=\"700\" height=\"409\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<p>Another common practice is to tag the image with the git commit ID, thereby linking the version control with the built images. You can automate this pretty easily with <code>git rev-parse<\/code>:<\/p>\n<pre>docker build -t vicerust\/core:$(git rev-parse --verify HEAD) .<\/pre>\n<p>Once an image is tagged, you can push it to the registry with <code>docker push<\/code>, passing in the <code>repository\/image<\/code>\u00a0name:<\/p>\n<pre>docker push repository\/image<\/pre>\n<p>From there, you\u2019re able to access it in <code>docker run<\/code>\u00a0as normal. If you don\u2019t specify a tag, <code>docker run<\/code>\u00a0automatically uses <code>latest<\/code>.<\/p>\n<h2 role=\"heading\" aria-level=\"2\"><span class=\"ez-toc-section\" id=\"Latest_Doesnt_Always_Mean_%E2%80%9CLatest%E2%80%9D\"><\/span>Latest Doesn\u2019t Always Mean \u201cLatest\u201d<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>The <code>\"Latest\"<\/code>\u00a0tag is a bit confusing. Despite how the name sounds, it doesn\u2019t always point to the latest release. It\u2019s simply a special tag that gets assigned automatically whenever you don\u2019t specify a tag. This has the effect of avoiding tags altogether and just pushing a \u201clatest\u201d version.<\/p>\n<p>You can use the latest tag either by just not specifying a specific tag:<\/p>\n<pre> docker build -t repository\/image .<\/pre>\n<p>Or by manually tagging an image as <code>latest<\/code>:<\/p>\n<pre> docker build -t repository\/image:latest .<\/pre>\n<p>which works well if you\u2019re only using the latest tag. But if you want to also use version ID tags, you\u2019ll need to double-tag your images every time, which can lead to \u201clatest\u201d not always meaning the last built image. It\u2019s good practice to avoid using <code>latest<\/code>\u00a0alongside other tags to prevent this confusion. Just version your tags, every time, either with manual patch numbers or with git commit IDs.\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\/5631\/how-do-docker-tags-work\/\" target=\"_blank\" rel=\"noopener\">Source<\/a><\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>&#8220;#How Do Docker Tags Work? \u2013 CloudSavvy IT&#8221; Docker images use registries for version control, such as the Docker Hub that hosts public images for anyone to download and run. However, before uploading an image to the Hub or any registry, you must give it the proper tags. Container vs. Image It\u2019s important to understand&#8230;<\/p>\n","protected":false},"author":1,"featured_media":301505,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"fifu_image_url":"https:\/\/www.cloudsavvyit.com\/p\/uploads\/2019\/06\/c454d054.png","fifu_image_alt":"","footnotes":""},"categories":[18],"tags":[],"class_list":["post-301504","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\/301504","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=301504"}],"version-history":[{"count":0,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/posts\/301504\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/media\/301505"}],"wp:attachment":[{"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/media?parent=301504"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/categories?post=301504"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/tags?post=301504"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}