{"id":498052,"date":"2022-10-04T03:48:19","date_gmt":"2022-10-04T00:48:19","guid":{"rendered":"https:\/\/en.buradabiliyorum.com\/how-to-store-docker-images-and-containers-on-an-external-drive\/"},"modified":"2022-10-04T03:48:19","modified_gmt":"2022-10-04T00:48:19","slug":"how-to-store-docker-images-and-containers-on-an-external-drive","status":"publish","type":"post","link":"https:\/\/buradabiliyorum.com\/en\/how-to-store-docker-images-and-containers-on-an-external-drive\/","title":{"rendered":"#How to Store Docker Images and Containers on an External Drive"},"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-6a285faaf10fc\" 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-6a285faaf10fc\" 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-store-docker-images-and-containers-on-an-external-drive\/#%E2%80%9CHow_to_Store_Docker_Images_and_Containers_on_an_External_Drive%E2%80%9D\" >&#8220;How to Store Docker Images and Containers on an External Drive&#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-store-docker-images-and-containers-on-an-external-drive\/#Preparation\" >Preparation<\/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-store-docker-images-and-containers-on-an-external-drive\/#Changing_Your_Data_Directory\" >Changing Your Data Directory<\/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-store-docker-images-and-containers-on-an-external-drive\/#Changing_the_Data_Directory_Without_a_Restart\" >Changing the Data Directory Without a Restart<\/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-store-docker-images-and-containers-on-an-external-drive\/#What_Actually_Changes\" >What Actually Changes?<\/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-store-docker-images-and-containers-on-an-external-drive\/#One-Time_Use_of_a_Different_Data_Directory\" >One-Time Use of a Different Data Directory<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/buradabiliyorum.com\/en\/how-to-store-docker-images-and-containers-on-an-external-drive\/#Summary\" >Summary<\/a><\/li><\/ul><\/li><\/ul><\/nav><\/div>\n<h1><span class=\"ez-toc-section\" id=\"%E2%80%9CHow_to_Store_Docker_Images_and_Containers_on_an_External_Drive%E2%80%9D\"><\/span>&#8220;How to Store Docker Images and Containers on an External Drive&#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-805981\" data-pagespeed-no-defer=\"\" src=\"https:\/\/www.howtogeek.com\/wp-content\/uploads\/2022\/05\/Docker-New.jpeg?width=1198&amp;trim=1,1&amp;bg-color=000&amp;pad=1,1\" alt=\"Graphic showing the Docker logo\" width=\"1600\" height=\"900\"\/><\/p>\n<p>Docker stores <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 images, running containers, and persistent volume data in a single shared directory root on your system drive. You can customize your configuration to use an external drive, network share, or second internal disc if you need to add storage to your installation.<\/p>\n<h2 id=\"preparation\"><span class=\"ez-toc-section\" id=\"Preparation\"><\/span>Preparation<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>The main part of this guide applies to Docker Engine for Linux and Docker Desktop on Windows and Mac. You\u2019ll need to find your Docker <code>daemon.json<\/code> file on all three platforms. This will be in one of the following locations:<\/p>\n<ul>\n<li><code>\/etc\/docker\/daemon.json<\/code> on Linux.<\/li>\n<li><code>%programdata%\\docker\\config\\daemon.json<\/code> on Windows.<\/li>\n<li><code>~\/Library\/Containers\/com.docker.docker\/Data\/database\/com.docker.driver.amd64-linux\/etc\/docker\/daemon.json<\/code> on Mac.<\/li>\n<\/ul>\n<p>Docker advises that Windows and Mac users update the config file <a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/github.com\/docker\/docker.github.io\/issues\/2643\">via the UI<\/a>, instead of manually applying changes in a text editor. You can access the settings screen by heading to Preferences &gt; Docker Engine &gt; Edit file in the Docker Desktop interface.<\/p>\n<h2 id=\"changing-your-data-directory\"><span class=\"ez-toc-section\" id=\"Changing_Your_Data_Directory\"><\/span>Changing Your Data Directory<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>The location of Docker\u2019s data directory is controlled by the <code>data-root<\/code> setting in your config file. Old Docker versions released prior to 17.06 used <code>graph<\/code> instead. You can check the version you\u2019ve got by running the <code>docker version<\/code> command.<\/p>\n<pre>$ docker version&#13;\n...&#13;\nServer: Docker Engine - Community&#13;\n  Engine:&#13;\n    Version: 20.10.17<\/pre>\n<p>Find or add the relevant key inside the config file. Set your desired directory path as its value. Here\u2019s a Linux example that\u2019ll store Docker data to an external drive mounted in the filesystem:<\/p>\n<div class=\"wp-geshi-highlight-wrap5\">\n<div class=\"wp-geshi-highlight-wrap4\">\n<div class=\"wp-geshi-highlight-wrap3\">\n<div class=\"wp-geshi-highlight-wrap2\">\n<div class=\"wp-geshi-highlight-wrap\">\n<div class=\"wp-geshi-highlight\">\n<div class=\"json\">\n<pre class=\"de1\">{&#13;\n    \"data-root\": \"\/mnt\/docker-data\"&#13;\n}<\/pre>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<p>You must restart the Docker daemon after you make the change:<\/p>\n<pre>$ sudo service docker restart<\/pre>\n<p>Docker Desktop can be restarted on Windows and Mac by exiting it and then launching a new instance.<\/p>\n<p>You should copy the contents of your current data directory to the new path if you want to retain your existing content. Otherwise you\u2019ll start with a clean slate, unable to access previously created containers and images.<\/p>\n<pre>$ sudo rsync -aSv \/var\/lib\/docker\/ \/mnt\/docker-data<\/pre>\n<h2 id=\"changing-the-data-directory-without-a-restart\"><span class=\"ez-toc-section\" id=\"Changing_the_Data_Directory_Without_a_Restart\"><\/span>Changing the Data Directory Without a Restart<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>You can move your data directory without restarting the daemon by creating a symlink from <code>\/var\/lib\/docker<\/code> to your new location. This could be useful if you\u2019re running out of space on a host where an unscheduled Docker service restart isn\u2019t a viable option.<\/p>\n<p>Copy your existing Docker data to your new directory:<\/p>\n<pre>$ sudo rsync -aSv \/var\/lib\/docker\/ \/mnt\/docker-data<\/pre>\n<p>Then create a symlink that resolves <code>\/var\/lib\/docker<\/code> to the target location:<\/p>\n<pre>$ sudo ln -s \/mnt\/docker-data\/ \/var\/lib\/docker<\/pre>\n<p>Don\u2019t use this technique for workloads that rapidly modify filesystem data. There\u2019s a risk of inconsistencies occurring if data gets written in the time between you copying the existing directory and creating the symlink.<\/p>\n<h2 id=\"what-actually-changes\"><span class=\"ez-toc-section\" id=\"What_Actually_Changes\"><\/span>What Actually Changes?<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Changing Docker\u2019s root directory affects all the different data types that the daemon stores. This includes your images, containers, installed plugins, Swarm configuration, and volumes, as well as the Docker build cache.<\/p>\n<p>Modifying the path will write all this data to your new location. You can\u2019t selectively move specific types to separate mount points. This means it\u2019s important to select a storage location that will offer good overall performance. Using a slow external drive could harm the responsiveness of <code>docker<\/code> CLI operations, even if it would suit certain types of data such as long-term image storage.<\/p>\n<p>In the absence of per-type data path support, pruning unused resources can be a better way to manage Docker\u2019s storage requirements. Instead of allocating Docker more space, clean up redundant assets and push unused images to a separate central registry. This can free up considerable space on your host.<\/p>\n<h2 id=\"one-time-use-of-a-different-data-directory\"><span class=\"ez-toc-section\" id=\"One-Time_Use_of_a_Different_Data_Directory\"><\/span>One-Time Use of a Different Data Directory<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>You can manually start Docker Engine with a specific data directory by passing the <code>--data-root<\/code> flag when you start the daemon. This can be used to switch between data directories or run a clean instance without your existing data.<\/p>\n<pre>$ sudo \/usr\/bin\/dockerd --data-root \/mnt\/docker-data<\/pre>\n<p>The flag will override the directory path specified by the <code>daemon.json<\/code> file. The configured directory will remain intact so you can revert to that instance in the future.<\/p>\n<h2 id=\"summary\"><span class=\"ez-toc-section\" id=\"Summary\"><\/span>Summary<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Docker stores all its data including built and pulled images, created containers, and volumes within a single directory tree. The root is usually <code>\/var\/lib\/docker<\/code> but you can customize it by adding a setting to your config file or supplying the <code>--data-root<\/code> flag when you start the daemon.<\/p>\n<p>Changing the data directory means your existing data won\u2019t appear in Docker unless you copy it to the new path. You can use this feature to maintain several independent Docker storage repositories, such as one for personal projects and another for work. You\u2019ll need to restart the daemon before you switch contexts though, as only one instance can run concurrently.<\/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\/how-to-store-docker-images-and-containers-on-an-external-drive\/\" target=\"_blank\" rel=\"noopener\">Source<\/a><\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>&#8220;How to Store Docker Images and Containers on an External Drive&#8221; Docker stores downloaded images, running containers, and persistent volume data in a single shared directory root on your system drive. You can customize your configuration to use an external drive, network share, or second internal disc if you need to add storage to your&#8230;<\/p>\n","protected":false},"author":1,"featured_media":498053,"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-New.jpeg?height=200p&trim=2,2,2,2","fifu_image_alt":"","footnotes":""},"categories":[18],"tags":[],"class_list":["post-498052","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\/498052","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=498052"}],"version-history":[{"count":0,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/posts\/498052\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/media\/498053"}],"wp:attachment":[{"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/media?parent=498052"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/categories?post=498052"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/tags?post=498052"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}