{"id":342186,"date":"2021-09-21T15:00:18","date_gmt":"2021-09-21T12:00:18","guid":{"rendered":"https:\/\/en.buradabiliyorum.com\/how-to-check-disk-space-usage-for-docker-images-containers-cloudsavvy-it\/"},"modified":"2021-09-21T15:00:18","modified_gmt":"2021-09-21T12:00:18","slug":"how-to-check-disk-space-usage-for-docker-images-containers-cloudsavvy-it","status":"publish","type":"post","link":"https:\/\/buradabiliyorum.com\/en\/how-to-check-disk-space-usage-for-docker-images-containers-cloudsavvy-it\/","title":{"rendered":"#How to Check Disk Space Usage for Docker Images &#038; Containers \u2013 CloudSavvy IT"},"content":{"rendered":"<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_85 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-6a424670861be\" 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-6a424670861be\" 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-to-check-disk-space-usage-for-docker-images-containers-cloudsavvy-it\/#Doing_a_Quick_Check\" >Doing a Quick Check<\/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-to-check-disk-space-usage-for-docker-images-containers-cloudsavvy-it\/#Cleaning_Docker_Images\" >Cleaning Docker 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-check-disk-space-usage-for-docker-images-containers-cloudsavvy-it\/#Checking_Running_Container_Usage\" >Checking Running Container Usage<\/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\/how-to-check-disk-space-usage-for-docker-images-containers-cloudsavvy-it\/#Debugging_Mounts_Binds_and_Volumes\" >Debugging Mounts (Binds and Volumes)<\/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\/how-to-check-disk-space-usage-for-docker-images-containers-cloudsavvy-it\/#Pruning_Containers_And_Volumes\" >Pruning Containers And Volumes<\/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\/how-to-check-disk-space-usage-for-docker-images-containers-cloudsavvy-it\/#Manually_Debugging\" >Manually Debugging<\/a><\/li><\/ul><\/nav><\/div>\n<p><strong>&#8220;#How to Check Disk Space Usage for Docker Images &amp; Containers \u2013 CloudSavvy IT&#8221;<\/strong><\/p>\n<div id=\"article-content-area\">\n<img loading=\"lazy\" decoding=\"async\" class=\"type:primaryImage alignnone size-full wp-image-14169\" 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\" 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\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<p>With containerized <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>lications running in isolated environments, it can be harder than usual to track down problems with applications using too much storage space. Fortunately, Docker provides commands for managing container disk usage.<\/p>\n<h2 role=\"heading\" aria-level=\"2\"><span class=\"ez-toc-section\" id=\"Doing_a_Quick_Check\"><\/span>Doing a Quick Check<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>And if you want to check how much space Docker is using, you can use the built in command\u00a0<code>docker system df<\/code>, as well as the Linux command <code>du<\/code>\u00a0to get the size of the entire directory.<\/p>\n<pre>docker system df&#13;\nsudo du -sh \/var\/lib\/docker\/<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-14211\" src=\"https:\/\/www.cloudsavvyit.com\/p\/uploads\/2021\/09\/ad3a0cc0-1.jpg?trim=1,1&amp;bg-color=000&amp;pad=1,1\" alt=\"\" width=\"499\" height=\"93\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<p>This command shows static images, containers that have made changes to their filesystem (e.g., log files), and volumes bound to the containers.<\/p>\n<p>However, this isn\u2019t entirely accurate\u2014here, I have many containers running, but they\u2019re all storing data in bind mounts on the host OS, not volumes.<\/p>\n<h2 role=\"heading\" aria-level=\"2\"><span class=\"ez-toc-section\" id=\"Cleaning_Docker_Images\"><\/span>Cleaning Docker Images<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Docker Images are different than running containers; they\u2019re the files that you download from the Docker Hub to launch a container from. They\u2019re usually pretty big, containing all the necessary code to run a basic OS and your application.<\/p>\n<p>Each version of an image is separate, but it\u2019s stored in layers, so multiple new versions won\u2019t take up twice as much storage space. You can view all images with <code>image ls<\/code>:<\/p>\n<pre>docker image ls<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-14171\" src=\"https:\/\/www.cloudsavvyit.com\/p\/uploads\/2021\/09\/377ab599.png?trim=1,1&amp;bg-color=000&amp;pad=1,1\" alt=\"\" width=\"545\" height=\"285\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<p>Cleaning these is easy; you don\u2019t want to remove images of running containers, of course, but removing old images is fine\u2014they\u2019ll simply be re-downloaded when needed.<\/p>\n<p>You can prune all images, or manually delete one by ID:<\/p>\n<pre>docker image prune -a&#13;\ndocker image rm 3a8d8f76e7f8f<\/pre>\n<h2 role=\"heading\" aria-level=\"2\"><span class=\"ez-toc-section\" id=\"Checking_Running_Container_Usage\"><\/span>Checking Running Container Usage<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Containers are a bit trickier to track down, since they can use data in many different ways:<\/p>\n<ul>\n<li><strong>Underlying image<\/strong>: each container will need to store its image, but this is reused across containers.<\/li>\n<li><strong>Modification layer<\/strong>: if a container writes to its filesystem, such as log files, it will be saved in a new layer on top of the underlying image. This is unique to each container.<\/li>\n<li><strong>Volumes<\/strong>: containers can have virtual drives mounted to them, which store data directly on disk outside the Docker storage system.<\/li>\n<li><strong>Bind Mounts<\/strong>: containers can optionally access directories on the host directly.<\/li>\n<\/ul>\n<p>Everything except bind mounts will show up in <code>docker system df<\/code>\u00a0output. If you want to view stats for each container, Docker provides a flag for the <code>ps<\/code>\u00a0command to list the usage:<\/p>\n<pre>docker ps --size<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-14212\" src=\"https:\/\/www.cloudsavvyit.com\/p\/uploads\/2021\/09\/4c0a6ca8.jpg?trim=1,1&amp;bg-color=000&amp;pad=1,1\" alt=\"\" width=\"466\" height=\"184\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<p>Here, this shows the size on disk, as well as the virtual size (which includes the shared underlying image). Since these containers aren\u2019t using any storage outside their bind mounts, the size is zero bytes.<\/p>\n<pre\/>\n<h2 role=\"heading\" aria-level=\"2\"><span class=\"ez-toc-section\" id=\"Debugging_Mounts_Binds_and_Volumes\"><\/span>Debugging Mounts (Binds and Volumes)<span class=\"ez-toc-section-end\"><\/span><\/h2>\nTo view mount usage, for both direct bind mounts and managed volumes, you\u2019ll have to get the size of them from the host OS. If you don\u2019t know where they are, you can run <code>docker container ls<\/code>\u00a0to get a container\u2019s ID, and then run <code>docker inspect<\/code>\u00a0to grab the mount info:\n<pre>docker inspect a1c904020044 -f '{{json .Mounts}}'&#13;\n&#13;\n<!--StartFragment -->[{\"Type\":\"bind\",\"Source\":\"\/home\/daemon-data\/921ff235-5075-4d64-b977-8d02cc3dacc9\",\"Destination\":\"\/home\/container\",\"Mode\":\"\",\"RW\":true,\"Propagation\":\"rprivate\"}]&#13;\n<!--EndFragment --><\/pre>\n<p>Then, you can check the total size with <code>du -sh<\/code>:<\/p>\n<pre>sudo du -sh \/path\/to\/mount\/<\/pre>\n<h2 role=\"heading\" aria-level=\"2\"><span class=\"ez-toc-section\" id=\"Pruning_Containers_And_Volumes\"><\/span>Pruning Containers And Volumes<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Docker never removes containers or volumes (unless you run containers with the <code>--rm<\/code>\u00a0flag), as doing so could lose your data. However, you may have old data backed up that needs to be garbage collected.<\/p>\n<p>Much like images, Docker provides a <code>prune<\/code>\u00a0command for containers and volumes:<\/p>\n<pre>docker container prune&#13;\n&#13;\ndocker volume prune<\/pre>\n<h2 role=\"heading\" aria-level=\"2\"><span class=\"ez-toc-section\" id=\"Manually_Debugging\"><\/span>Manually Debugging<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>If you have direct access to the server running Docker, you can pop open a shell in the container:<\/p>\n<pre>sudo docker exec -it containerID \/bin\/bash<\/pre>\n<p>and run <code>du -sh<\/code>\u00a0on the entire thing, which will return <em>all data,<\/em> including the image size, data on bind mounts, and data in volumes.<\/p>\n<pre>sudo du -sh \/<\/pre>\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\/14208\/how-to-check-disk-space-usage-for-docker-images-containers\/\" target=\"_blank\" rel=\"noopener\">Source<\/a><\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>&#8220;#How to Check Disk Space Usage for Docker Images &amp; Containers \u2013 CloudSavvy IT&#8221; With containerized applications running in isolated environments, it can be harder than usual to track down problems with applications using too much storage space. Fortunately, Docker provides commands for managing container disk usage. Doing a Quick Check And if you want&#8230;<\/p>\n","protected":false},"author":1,"featured_media":342187,"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-342186","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\/342186","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=342186"}],"version-history":[{"count":0,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/posts\/342186\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/media\/342187"}],"wp:attachment":[{"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/media?parent=342186"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/categories?post=342186"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/tags?post=342186"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}