{"id":491178,"date":"2022-09-08T03:48:13","date_gmt":"2022-09-08T00:48:13","guid":{"rendered":"https:\/\/en.buradabiliyorum.com\/what-are-dangling-docker-images\/"},"modified":"2022-09-08T03:48:13","modified_gmt":"2022-09-08T00:48:13","slug":"what-are-dangling-docker-images","status":"publish","type":"post","link":"https:\/\/buradabiliyorum.com\/en\/what-are-dangling-docker-images\/","title":{"rendered":"#What Are Dangling Docker Images?"},"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-6a25e3592cac2\" 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-6a25e3592cac2\" 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\/what-are-dangling-docker-images\/#%E2%80%9CWhat_Are_Dangling_Docker_Images%E2%80%9D\" >&#8220;What Are Dangling Docker Images?&#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\/what-are-dangling-docker-images\/#What_Is_a_Dangling_Image\" >What Is a Dangling Image?<\/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\/what-are-dangling-docker-images\/#How_Are_Dangling_Images_Created\" >How Are Dangling Images Created?<\/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\/what-are-dangling-docker-images\/#Can_You_Use_a_Dangling_Image\" >Can You Use a Dangling Image?<\/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\/what-are-dangling-docker-images\/#Cleaning_Up_Dangling_Images\" >Cleaning Up Dangling Images<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/buradabiliyorum.com\/en\/what-are-dangling-docker-images\/#Summary\" >Summary<\/a><\/li><\/ul><\/li><\/ul><\/nav><\/div>\n<h1><span class=\"ez-toc-section\" id=\"%E2%80%9CWhat_Are_Dangling_Docker_Images%E2%80%9D\"><\/span>&#8220;What Are Dangling Docker Images?&#8221;<span class=\"ez-toc-section-end\"><\/span><\/h1>\n<div>\n<img loading=\"lazy\" decoding=\"async\" class=\"type:primaryImage alignnone size-full wp-image-803108\" data-pagespeed-no-defer=\"\" src=\"https:\/\/www.howtogeek.com\/wp-content\/uploads\/2022\/05\/Docker.jpeg?width=1198&amp;trim=1,1&amp;bg-color=000&amp;pad=1,1\" alt=\"Docker logo\" width=\"1602\" height=\"902\"\/><\/p>\n<p>Dangling Docker images are untagged and unused layers that exist on your host\u2019s filesystem. You might not be aware of their presence and they\u2019re usually unwanted garbage.<\/p>\n<p>In this article you\u2019ll learn how dangling images arise and what you can do to clean them up. It\u2019s a good idea to periodically inspect how many dangling images you have so you can avoid wasting your disk\u2019s capacity.<\/p>\n<h2 id=\"what-is-a-dangling-image\"><span class=\"ez-toc-section\" id=\"What_Is_a_Dangling_Image\"><\/span>What Is a Dangling Image?<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>A dangling image is simply an unused image that\u2019s got no name and tag. You can easily spot dangling images when you run the <code>docker images<\/code> command because they show up as <code>&lt;none&gt;:&lt;none&gt;<\/code>.<\/p>\n<p>In this example, the first image in the list is a dangling image:<\/p>\n<pre>$ docker images&#13;\n&lt;none&gt;                              &lt;none&gt;    509bc96b727d   2 months ago    55.3MB&#13;\nmysql                               5.7       f26e21ddd20d   4 months ago    450MB&#13;\ngcr.io\/k8s-minikube\/kicbase         v0.0.30   1312ccd2422d   6 months ago    1.14GB&#13;\nhello-world                         latest    feb5d9fea6a5   11 months ago   13.3kB<\/pre>\n<p>The image is untagged but still lingering on your system. In this case 55.3 MB of disk space is being consumed.<\/p>\n<p>You can verify the image is dangling and not just unused by checking whether any container references it:<\/p>\n<pre>$ docker ps -a&#13;\nCONTAINER ID   IMAGE                                      COMMAND                  CREATED          STATUS                   &#13;\n2aa683500ee0   gcr.io\/k8s-minikube\/kicbase:v0.0.30        \"\/usr\/local\/bin\/entr...\"   18 hours ago     Exited (130) 18 hours ago<\/pre>\n<p>No container references the <code>&lt;none&gt;:&lt;none&gt;<\/code> image with ID <code>509bc96b727d<\/code> so it\u2019s definitely dangling. Note that the MySQL and Hello World images <em>don\u2019t<\/em> class as dangling \u2013 despite being unused by containers, they\u2019re properly tagged so it\u2019s assumed you\u2019ll want to keep them.<\/p>\n<h2 id=\"how-are-dangling-images-created\"><span class=\"ez-toc-section\" id=\"How_Are_Dangling_Images_Created\"><\/span>How Are Dangling Images Created?<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Dangling images are usually created when an existing image gets superseded by a new build. Here\u2019s a simple Dockerfile to demonstrate what h<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>ens:<\/p>\n<pre>FROM alpine:latest&#13;\nCOPY demo.txt \/demo.txt<\/pre>\n<p>Create a file called <code>demo.txt<\/code> in your working directory and add some content to it:<\/p>\n<pre>$ echo 1 &gt; demo.txt<\/pre>\n<p>Now build your image with <code>docker build<\/code>:<\/p>\n<pre>$ docker build -t demo:latest .<\/pre>\n<p>Run the <code>docker images<\/code> command to see your new image:<\/p>\n<pre>REPOSITORY                          TAG       IMAGE ID       CREATED          SIZE&#13;\ndemo                                latest    40395b6c1362   24 seconds ago   5.54MB<\/pre>\n<p>Now modify the contents of <code>demo.txt<\/code> and rebuild your image:<\/p>\n<pre>$ echo 2 &gt; demo.txt&#13;\n$ docker build -t demo:latest .<\/pre>\n<p>The same image tag is used \u2013 <code>demo:latest<\/code> \u2013 so this build supersedes the first one. Run <code>docker images<\/code> to see the effect:<\/p>\n<pre>REPOSITORY                          TAG       IMAGE ID       CREATED         SIZE&#13;\ndemo                                latest    3d5052e52b4c   3 seconds ago   5.54MB&#13;\n&lt;none&gt;                              &lt;none&gt;    40395b6c1362   59 seconds ago   5.54MB<\/pre>\n<p>The new image has been created with ID <code>3d5052e52b4c<\/code> and the <code>demo:latest<\/code> tag. The first image, ID <code>40395b6c1362<\/code>, still exists but has been untagged. It now shows as <code>&lt;none&gt;:&lt;none&gt;<\/code>. This image has become a dangling image as no containers use it.<\/p>\n<h2 id=\"can-you-use-a-dangling-image\"><span class=\"ez-toc-section\" id=\"Can_You_Use_a_Dangling_Image\"><\/span>Can You Use a Dangling Image?<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Dangling images function like any other image. The only difference is the missing tag. You can start a container from a dangling image by directly referencing the image\u2019s ID:<\/p>\n<pre>$ docker run -it 40395b6c1362 sh&#13;\n\/ #<\/pre>\n<p>Technically, the image is no longer dangling, because it\u2019s now actively used by a container. It\u2019s common for containers to end up with a <code>none<\/code> image if you remove or rebuild the tag they used. Containers with an untagged image will show the image\u2019s ID in the <code>IMAGE<\/code> column when you run <code>docker ps<\/code>, instead of the usual tag.<\/p>\n<pre>$ docker ps&#13;\nCONTAINER ID   IMAGE                                      COMMAND                  CREATED         STATUS        PORTS                NAMES&#13;\n26d5609ba75c   40395b6c1362                               \"sh\"                     2 seconds ago   Up 1 second                        inspiring_lederberg&#13;\n91ab866b59a2   portainer\/portainer-ce                     \"\/portainer\"             2 weeks ago     Up 2 days     8000\/tcp, 9443\/tcp   portainer_portainer_1<\/pre>\n<h2 id=\"cleaning-up-dangling-images\"><span class=\"ez-toc-section\" id=\"Cleaning_Up_Dangling_Images\"><\/span>Cleaning Up Dangling Images<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>You can delete a single dangling image using the <code>docker rmi<\/code> command, just like any other image. Because the image won\u2019t be tagged, you\u2019ll need to identify it by its ID.<\/p>\n<pre>$ docker rmi 40395b6c1362<\/pre>\n<p>A better way to clean up many dangling images is the <code>docker image prune<\/code> command. This will automatically remove all the dangling images on your Docker host.<\/p>\n<pre>$ docker image prune&#13;\nTotal reclaimed space: 5.54 MB<\/pre>\n<p>The command\u2019s output shows the amount of disk space that was freed. Check whether your images are actually dangling if nothing gets deleted. It\u2019s not possible to remove images actively used by containers. You\u2019ll need to delete the containers with <code>docker rm<\/code> first, before you try to prune your images.<\/p>\n<p>You could find you\u2019ve got a dangling image that you actually want to reuse in the future. In this situation you can re-tag it with the <code>docker tag<\/code> command. This will make the image easier to identify and prevent it being targeted by future pruning operations.<\/p>\n<pre>$ docker tag 40395b6c1362 demo:latest<\/pre>\n<p>Images that display as <code>&lt;none&gt;:&lt;none&gt;<\/code> might not be dangling images. Confusingly, this situation also occurs for images created as the inter<a href=\"https:\/\/buradabiliyorum.com\/en\/category\/social-mediaa\/\" data-internallinksmanager029f6b8e52c=\"1\" title=\"Social Media\" target=\"_blank\" rel=\"noopener\">media<\/a>te layers during a build.<\/p>\n<p>Each step in a Dockerfile results in a new intermediate layer being created. The image produced at the end of the build gets assigned the tag you specify. The other intermediate layers remain untagged and can be viewed by running <code>docker images -a<\/code>.<\/p>\n<p>These layers are not dangling images because the later images in the build chain depend upon them. They\u2019re referenced by each successive layer and don\u2019t cause a disk space problem. You can stop intermediate layers being persisted to disk by including the <code>--rm<\/code> flag at build time:<\/p>\n<pre>$ docker build --rm -t demo:latest .<\/pre>\n<h2 id=\"summary\"><span class=\"ez-toc-section\" id=\"Summary\"><\/span>Summary<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Dangling images are untagged Docker images that aren\u2019t used by a container or depended on by a descendant. They usually serve no purpose but still consume disk space. You\u2019ll accumulate dangling images when you replace an existing tag by starting a new build.<\/p>\n<p>All dangling images show as <code>&lt;none&gt;:&lt;none&gt;<\/code> in the Docker CLI. Having too many of them can be overwhelming when you\u2019ve got dozens of images with no information about their true identity. Regularly running <code>docker images prune<\/code> will avoid disk space wastage and result in a shorter image list.<\/p>\n<\/div>\n<p><script>\n setTimeout(function(){\n  !function(f,b,e,v,n,t,s)\n  {if(f.fbq)return;n=f.fbq=function(){n.callMethod?\n  n.callMethod.apply(n,arguments):n.queue.push(arguments)};\n  if(!f._fbq)f._fbq=n;n.push=n;n.loaded=!0;n.version='2.0';\n  n.queue=[];t=b.createElement(e);t.async=!0;\n  t.src=v;s=b.getElementsByTagName(e)[0];\n  s.parentNode.insertBefore(t,s) } (window, document,'script',\n  'https:\/\/connect.facebook.net\/en_US\/fbevents.js');\n   fbq('init', '335401813750447');\n   fbq('track', 'PageView');\n  },3000);\n<\/script><\/p>\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.howtogeek.com\/devops\/what-are-dangling-docker-images\/\" target=\"_blank\" rel=\"noopener\">Source<\/a><\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>&#8220;What Are Dangling Docker Images?&#8221; Dangling Docker images are untagged and unused layers that exist on your host\u2019s filesystem. You might not be aware of their presence and they\u2019re usually unwanted garbage. In this article you\u2019ll learn how dangling images arise and what you can do to clean them up. It\u2019s a good idea to&#8230;<\/p>\n","protected":false},"author":1,"featured_media":491179,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"fifu_image_url":"https:\/\/www.howtogeek.com\/wp-content\/uploads\/2022\/05\/Docker.jpeg?height=200p&trim=2,2,2,2","fifu_image_alt":"","footnotes":""},"categories":[18],"tags":[],"class_list":["post-491178","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\/491178","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=491178"}],"version-history":[{"count":0,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/posts\/491178\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/media\/491179"}],"wp:attachment":[{"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/media?parent=491178"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/categories?post=491178"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/tags?post=491178"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}