{"id":339639,"date":"2021-09-15T14:43:12","date_gmt":"2021-09-15T11:43:12","guid":{"rendered":"https:\/\/en.buradabiliyorum.com\/where-are-docker-images-containers-stored-on-the-host-cloudsavvy-it\/"},"modified":"2021-09-15T14:43:12","modified_gmt":"2021-09-15T11:43:12","slug":"where-are-docker-images-containers-stored-on-the-host-cloudsavvy-it","status":"publish","type":"post","link":"https:\/\/buradabiliyorum.com\/en\/where-are-docker-images-containers-stored-on-the-host-cloudsavvy-it\/","title":{"rendered":"#Where Are Docker Images &#038; Containers Stored on the Host? \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-6a284c78bbc61\" 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-6a284c78bbc61\" 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\/where-are-docker-images-containers-stored-on-the-host-cloudsavvy-it\/#The_Difference_Between_Images_and_Containers\" >The Difference Between Images and Containers<\/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\/where-are-docker-images-containers-stored-on-the-host-cloudsavvy-it\/#Working_With_Docker_Image_Storage\" >Working With Docker Image Storage<\/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\/where-are-docker-images-containers-stored-on-the-host-cloudsavvy-it\/#Working_With_Docker_Container_Storage\" >Working With Docker Container\u00a0Storage<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/buradabiliyorum.com\/en\/where-are-docker-images-containers-stored-on-the-host-cloudsavvy-it\/#Accessing_Volumes\" >Accessing Volumes<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/buradabiliyorum.com\/en\/where-are-docker-images-containers-stored-on-the-host-cloudsavvy-it\/#Modifying_a_Docker_Containers_Filesystem\" >Modifying a Docker Container\u2019s Filesystem<\/a><\/li><\/ul><\/li><\/ul><\/nav><\/div>\n<p><strong>&#8220;#Where Are Docker Images &amp; Containers Stored on the Host? \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 aligncenter\" 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>Docker uses two kinds of formats to represent running processes\u2014images, and containers, and both store data on your computer\u2019s drive. We\u2019ll talk about the commands Docker provides for handling data, and how you can use them to access image and container files.<\/p>\n<h2 role=\"heading\" aria-level=\"2\"><span class=\"ez-toc-section\" id=\"The_Difference_Between_Images_and_Containers\"><\/span>The Difference Between Images and Containers<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Images are what you create when you run <code>docker build<\/code>; they\u2019re stored in a container registry like the Docker Hub, and contain all the files and code to run an <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>. You can think of them like ISO files for a virtual machine operating system.<\/p>\n<p>Containers are created from images, and they\u2019re like the actual virtual machine that runs the application. You might have multiple containers running in parallel off the same image. Each container will have its own file system, optionally created with \u201cvolume mounts\u201d that bind data from the host to the container.<\/p>\n<h2 role=\"heading\" aria-level=\"2\"><span class=\"ez-toc-section\" id=\"Working_With_Docker_Image_Storage\"><\/span>Working With Docker Image Storage<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Images store the entire contents of the image on your drive. Whenever you pull an image from the internet, it\u2019s downloaded and stored, usually forever. Images can be very large, so this can add up over time, especially for laptops with limited storage.<\/p>\n<p>If you want to access the image data directly, it\u2019s usually stored in the following locations:<\/p>\n<ul>\n<li>Linux: <code>\/var\/lib\/docker\/<\/code><\/li>\n<li>Windows: <code>C:ProgramDataDockerDesktop<\/code><\/li>\n<li>macOS: <code>~\/Library\/Containers\/com.docker.docker\/Data\/vms\/0\/<\/code><\/li>\n<\/ul>\n<p>However, touching this data is likely a <strong>bad idea<\/strong>. Docker\u2019s storage is complicated, and actually varies wildly depending on <a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/github.com\/moby\/moby\/blob\/990a3e30fa66e7bd3df3c78c873c97c5b1310486\/daemon\/graphdriver\/driver.go#L37-L43\">what storage driver<\/a> it\u2019s using. Linux now defaults to <code>overlay2<\/code>\u00a0on most distros, which isn\u2019t even accessible for most end users. Messing with this can lead to data loss.<\/p>\n<p>Instead, Docker provides managed commands to handle images. You can view all versions of downloaded images with a simple command:<\/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>Luckily, it isn\u2019t as bad as it looks, since Docker images store versions incrementally. That means, whenever you download a new version, it only replaces the parts that were changed. If you frequently use the same image over and over, you probably won\u2019t rack up too much storage cost.<\/p>\n<p>However, if you use a lot of different images, you might have many images saved that aren\u2019t even used anymore. To clean these up, Docker provides a built-in command to run garbage collection. This will prune all images that have no references, i.e. not tagged or not referenced by any container.<\/p>\n<pre>docker image prune<\/pre>\n<p>To prune all old images not used by existing containers, run it with the <code>-a<\/code>\u00a0flag:<\/p>\n<pre>docker image prune -a<\/pre>\n<p>That covers the main use case, but there are a few more useful commands:<\/p>\n<ul>\n<li><code>inspect<\/code>: displays info about a container version.<\/li>\n<li><code>save &amp; load<\/code>: saves and loads images to a <code>tar<\/code>\u00a0archive.<\/li>\n<li><code>rm<\/code>: removes an image directly.<\/li>\n<li><code>pull\/push<\/code>: updates from a remote registry.<\/li>\n<li><code>history<\/code>: provides a changelog.<\/li>\n<\/ul>\n<h2 role=\"heading\" aria-level=\"2\"><span class=\"ez-toc-section\" id=\"Working_With_Docker_Container_Storage\"><\/span>Working With Docker Container\u00a0Storage<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>You can view all info about a container with <code>docker inspect<\/code>, which shows the filesystem drivers and data, as well as all the existing mounts and volumes.<\/p>\n<pre>docker inspect containerID<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-14174\" src=\"https:\/\/www.cloudsavvyit.com\/p\/uploads\/2021\/09\/5b7b9021-1.png?trim=1,1&amp;bg-color=000&amp;pad=1,1\" alt=\"\" width=\"1023\" height=\"366\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<p>Containers store data in two ways. First is the base filesystem, which is copied from the image and is unique to each container. Docker uses a \u201clower dir\u201d and \u201cupper dir,\u201d which are separate layers that get merged into one hybrid filesystem. The lower dir stores the base image data, and the upper dir stores everything that was changed at runtime, such as log files. In either case, the storage of these depends on the filesystem driver Docker is configured to use.<\/p>\n<p>Then, there are\u00a0<em>mounts<\/em>, which bind directories from the host to the container, usually managed automatically with a Docker feature called\u00a0<em><a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/docs.docker.com\/storage\/volumes\/#populate-a-volume-using-a-container\">volumes<\/a>.<\/em> These are stored normally, and are accessible to end users. If you\u2019re doing any work that requires you to modify data on running containers, you should probably be modifying a volume or bind mount.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Accessing_Volumes\"><\/span>Accessing Volumes<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>Bind mounts can be accessed directly, and are a great choice if you want to store config that\u2019s used for many containers, or store accessible data that persists across container restarts.<\/p>\n<p>If you want to modify data stored in volumes, you can do so too. They\u2019re stored in a standard format accessible from Linux:<\/p>\n<pre>\/var\/lib\/docker\/volumes\/volumeID\/_data<\/pre>\n<p>You can get the volume ID and information with <code>docker volume inspect<\/code>.<\/p>\n<p>Much like images, volumes can also become stale. You can remove them easily, but <a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/docs.docker.com\/storage\/volumes\/#backup-restore-or-migrate-data-volumes\">backing up and transferring them is a trickier process<\/a>.<\/p>\n<pre>docker volume prune&#13;\n&#13;\ndocker volume rm volumeID<\/pre>\n<h3><span class=\"ez-toc-section\" id=\"Modifying_a_Docker_Containers_Filesystem\"><\/span>Modifying a Docker Container\u2019s Filesystem<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>If you want to modify the container\u2019s filesystem, much like images, this is a\u00a0<strong>bad idea.<\/strong> In most cases, you should create a new version of the container with the updated changes, and deploy an update.<\/p>\n<p>However, if you want to make some quick changes without stopping the container, the best way is to just pop open a bash shell inside the container and modify it through Docker. Doing so is very easy\u2014run <code>docker exec<\/code>\u00a0on the container, and pass \u201cbash\u201d as the command:<\/p>\n<pre>docker exec -it container bash<\/pre>\n<p>From here, you are free to use normal Linux commands. If you want to do this remotely, you can install an SSH server in your container, and bind port 22 to another port on the host.<\/p>\n<p><strong>RELATED:<\/strong> <strong><em>How to SSH Into a Docker Container<\/em><\/strong>\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\/14168\/where-are-docker-images-containers-stored-on-the-host\/\" target=\"_blank\" rel=\"noopener\">Source<\/a><\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>&#8220;#Where Are Docker Images &amp; Containers Stored on the Host? \u2013 CloudSavvy IT&#8221; Docker uses two kinds of formats to represent running processes\u2014images, and containers, and both store data on your computer\u2019s drive. We\u2019ll talk about the commands Docker provides for handling data, and how you can use them to access image and container files&#8230;.<\/p>\n","protected":false},"author":1,"featured_media":339640,"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-339639","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\/339639","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=339639"}],"version-history":[{"count":0,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/posts\/339639\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/media\/339640"}],"wp:attachment":[{"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/media?parent=339639"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/categories?post=339639"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/tags?post=339639"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}