{"id":245,"date":"2023-11-11T17:51:13","date_gmt":"2023-11-11T17:51:13","guid":{"rendered":"https:\/\/pipeawk.com\/?p=245"},"modified":"2025-12-18T22:45:23","modified_gmt":"2025-12-18T22:45:23","slug":"relocate-docker-data-root-directory","status":"publish","type":"post","link":"https:\/\/pipeawk.com\/index.php\/2023\/11\/11\/relocate-docker-data-root-directory\/","title":{"rendered":"Relocate Docker Data Root Directory"},"content":{"rendered":"<p>Lately I had a need to move the Docker root directory to a different filesystem. After researching the item and saw that the documentation out there was limited and not very clear, I decided to write the necessary steps here.<\/p>\r\n<p>By default, on most systems, the\u00a0<strong>docker<\/strong> root directory is located in the directory\u00a0<strong>\/var\/lib\/docker<\/strong>, this directory is used to store thigs like images, volumes, and other different docker runtime items. In order to move this directory to a different location, let&#8217;s say\u00a0<strong>\/opt\/docker-root<\/strong>, there are few steps required, more specifically:<\/p>\r\n<p><!--more--><\/p>\r\n<ol>\r\n<li>Stop the docker daemon<\/li>\r\n<li>Create the filesystem mount point<\/li>\r\n<li>Move the content of the directory\u00a0<strong>\/var\/lib\/docker<\/strong> to\u00a0<strong>\/opt\/docker-root<\/strong><\/li>\r\n<li>Rename the directory\u00a0<strong>\/var\/lib\/docker<\/strong> to\u00a0<strong>\/var\/lib\/docker.old<\/strong><\/li>\r\n<li>Update the docker startup command<\/li>\r\n<li>Refresh the systemd configuration<\/li>\r\n<li>Start the docker daemon<\/li>\r\n<li>If the directory\u00a0<strong>\/var\/lib\/docker<\/strong> is not recreated and the command\u00a0<strong>docker images<\/strong> displays the installed images, you can safely delete the directory\u00a0<strong>\/var\/lib\/docker.old<\/strong><\/li>\r\n<\/ol>\r\n<p>Now, let&#8217;s discuss in details how to accomplish each of the items listed above, which they can variate depending on the operating system used, this guide assumes that you are using Ubuntu or Ubuntu derivative. If you are using something else, you might encounter differences in the commands, if you do, refer to the OS documentation for the alternative commands.<\/p>\r\n<h3>Stop the docker daemon<\/h3>\r\n<p>In order to stop the docker daemon, you would type the following command:<\/p>\r\n<blockquote>\r\n<p>systemctl stop docker<\/p>\r\n<\/blockquote>\r\n<p>If you installed docker using an alternative method, you should be familiar on how to stop the background process.<\/p>\r\n<h3>Create the filesystem and mountpoint<\/h3>\r\n<p>This step is heavily dependent on what type of filesystem you are running, the operating system you are using, etc. Create a filesystem goes beyond this guide. Plenty of guides on the internet on how to do that.<\/p>\r\n<h3>Move the file content to the new location<\/h3>\r\n<p>In order to move the content to the new location, you first copy the existing content with the following command:<\/p>\r\n<blockquote>\r\n<p>cp -a \/var\/lib\/docker\/* \/opt\/docker-root\/<\/p>\r\n<\/blockquote>\r\n<p>This command might take a while depending on how big the docker installation is, so be patent!<\/p>\r\n<p>The rename and delete in later steps will complete the move.<\/p>\r\n<h3>Update docker startup command<\/h3>\r\n<p>In this step we will instruct the dockerd command to use an alternative application root directory. If you using a recent Ubuntu distribution, you are using systemd, and the file will be located under \/etc. More precisely:<\/p>\r\n<blockquote>\r\n<div>\/etc\/systemd\/system\/multi-user.target.wants\/docker.service<\/div>\r\n<\/blockquote>\r\n<p>If the file is located elsewhere, refer to the installation of docker used to find the configuration file.<\/p>\r\n<p>Now, use your prefer editor to open and modify the following line in the file.<\/p>\r\n<p>From:<\/p>\r\n<blockquote>\r\n<p>ExecStart=\/usr\/bin\/dockerd -H fd:\/\/ &#8211;containerd=\/run\/containerd\/containerd.sock<\/p>\r\n<\/blockquote>\r\n<p>To:<\/p>\r\n<p><!--StartFragment --><\/p>\r\n<blockquote>\r\n<p>ExecStart=\/usr\/bin\/dockerd &#8211;data-root \/opt\/app\/docker-root -H fd:\/\/ &#8211;containerd=\/run\/containerd\/containerd.sock<\/p>\r\n<\/blockquote>\r\n<p>If you notice, the command line argument &#8211;data-root \/opt\/app\/docker-root has been added to the ExecStart variable. \/opt\/app\/docker-root is the default this guide is using, but you can use whatever location you prefer.<\/p>\r\n<p>Now on to the next step<\/p>\r\n<h3>Refresh systemd configuration<\/h3>\r\n<p>In order for the change to be picked up by systemd, use the following comand:<\/p>\r\n<blockquote>\r\n<p>systemd daemon-reload<\/p>\r\n<\/blockquote>\r\n<p>Now you can start the docker daemon with the new config applied.<\/p>\r\n<h3>Start the docker daemon<\/h3>\r\n<p>Much like the stop command, the start command is very similar:<\/p>\r\n<blockquote>\r\n<p>systemctl start docker<\/p>\r\n<\/blockquote>\r\n<h3>Examine the directory \/var\/lib for the presence of the docker directory<\/h3>\r\n<p>In order to verify that the root directory has been correctly moved. Do the following:<\/p>\r\n<ol>\r\n<li>Verify that the directory <strong>\/var\/lib\/docker<\/strong> does not exist after the daemon has loaded<\/li>\r\n<li>Use the command\u00a0<strong>docker images<\/strong> to verify that images are loaded from the new root directory<\/li>\r\n<li>If the above two steps are ok, you can safely delete the directory\u00a0<strong>\/var\/lib\/docker.old<\/strong><\/li>\r\n<\/ol>\r\n<p>At this point, the move is completed.<\/p>\r\n<p>Thank you for following this guide and type away!!!<\/p>\r\n<p><!--EndFragment --><\/p>\r\n","protected":false},"excerpt":{"rendered":"<p>Lately I had a need to move the Docker root directory to a different filesystem. After researching the item and saw that the documentation out there was limited and not very clear, I decided to write the necessary steps here. By default, on most systems, the\u00a0docker root directory is located in the directory\u00a0\/var\/lib\/docker, this directory &hellip; <a href=\"https:\/\/pipeawk.com\/index.php\/2023\/11\/11\/relocate-docker-data-root-directory\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Relocate Docker Data Root Directory&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"_uf_show_specific_survey":0,"_uf_disable_surveys":false,"footnotes":""},"categories":[3],"tags":[],"class_list":["post-245","post","type-post","status-publish","format-standard","hentry","category-unix"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/pipeawk.com\/index.php\/wp-json\/wp\/v2\/posts\/245","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/pipeawk.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/pipeawk.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/pipeawk.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/pipeawk.com\/index.php\/wp-json\/wp\/v2\/comments?post=245"}],"version-history":[{"count":8,"href":"https:\/\/pipeawk.com\/index.php\/wp-json\/wp\/v2\/posts\/245\/revisions"}],"predecessor-version":[{"id":261,"href":"https:\/\/pipeawk.com\/index.php\/wp-json\/wp\/v2\/posts\/245\/revisions\/261"}],"wp:attachment":[{"href":"https:\/\/pipeawk.com\/index.php\/wp-json\/wp\/v2\/media?parent=245"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/pipeawk.com\/index.php\/wp-json\/wp\/v2\/categories?post=245"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/pipeawk.com\/index.php\/wp-json\/wp\/v2\/tags?post=245"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}