<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom"><title>Guguweb - containers</title><link href="https://www.guguweb.com/" rel="alternate"></link><link href="https://www.guguweb.com/feeds/containers.atom.xml" rel="self"></link><id>https://www.guguweb.com/</id><updated>2022-01-14T21:14:30+01:00</updated><subtitle>Freelance developer and sysadmin</subtitle><entry><title>How to move docker data directory to another location on Ubuntu</title><link href="https://www.guguweb.com/2019/02/07/how-to-move-docker-data-directory-to-another-location-on-ubuntu/" rel="alternate"></link><published>2019-02-07T10:33:47+00:00</published><updated>2022-01-14T21:14:30+01:00</updated><author><name>Augusto Destrero</name></author><id>tag:www.guguweb.com,2019-02-07:/2019/02/07/how-to-move-docker-data-directory-to-another-location-on-ubuntu/</id><summary type="html">&lt;p&gt;&lt;a href="https://www.docker.com/"&gt;Docker&lt;/a&gt; is a popular container management platform that can dramatically speed up your development workflow. It is available as a package on major Linux distributions, including Ubuntu.&lt;/p&gt;
&lt;p&gt;The standard data directory used for docker is /var/lib/docker, and since this directory will store all your images, volumes, etc. it …&lt;/p&gt;</summary><content type="html">&lt;p&gt;&lt;a href="https://www.docker.com/"&gt;Docker&lt;/a&gt; is a popular container management platform that can dramatically speed up your development workflow. It is available as a package on major Linux distributions, including Ubuntu.&lt;/p&gt;
&lt;p&gt;The standard data directory used for docker is /var/lib/docker, and since this directory will store all your images, volumes, etc. it can become quite large in a relative small amount of time.&lt;/p&gt;
&lt;p&gt;If you want to move the docker data directory on another location you can follow the following simple steps.&lt;/p&gt;
&lt;div class="toc"&gt;&lt;span class="toctitle"&gt;Table of Contents&lt;/span&gt;&lt;ul&gt;
&lt;li&gt;&lt;a href="#1-stop-the-docker-daemon"&gt;1. Stop the docker daemon&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="#2-add-a-configuration-file-to-tell-the-docker-daemon-what-is-the-location-of-the-data-directory"&gt;2. Add a configuration file to tell the docker daemon what is the location of the data directory&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="#3-copy-the-current-data-directory-to-the-new-one"&gt;3. Copy the current data directory to the new one&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="#4-rename-the-old-docker-directory"&gt;4. Rename the old docker directory&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="#5-restart-the-docker-daemon"&gt;5. Restart the docker daemon&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="#6-test"&gt;6. Test&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="#7-extra-step-remote-debug-on-your-docker-container"&gt;7. Extra step: remote debug on your Docker container!&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;h2 id="1-stop-the-docker-daemon"&gt;1. Stop the docker daemon&lt;/h2&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;sudo service docker stop
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;h2 id="2-add-a-configuration-file-to-tell-the-docker-daemon-what-is-the-location-of-the-data-directory"&gt;2. Add a configuration file to tell the docker daemon what is the location of the data directory&lt;/h2&gt;
&lt;p&gt;Using your preferred text editor add a file named &lt;strong&gt;daemon.json&lt;/strong&gt; under the directory &lt;strong&gt;/etc/docker&lt;/strong&gt;. The file should have this content:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;quot;data-root&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;&amp;quot;/path/to/your/docker&amp;quot;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;of course you should customize the location &amp;#8220;/path/to/your/docker&amp;#8221; with the path you want to use for your new docker data directory.&lt;/p&gt;
&lt;h2 id="3-copy-the-current-data-directory-to-the-new-one"&gt;3. Copy the current data directory to the new one&lt;/h2&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class="n"&gt;sudo&lt;/span&gt; &lt;span class="n"&gt;rsync&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;aP&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="k"&gt;var&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;lib&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;docker&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;path&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;to&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;your&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;docker&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;h2 id="4-rename-the-old-docker-directory"&gt;4. Rename the old docker directory&lt;/h2&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class="n"&gt;sudo&lt;/span&gt; &lt;span class="n"&gt;mv&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="k"&gt;var&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;lib&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;docker&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="k"&gt;var&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;lib&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;docker&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;old&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;This is just a sanity check to see that everything is ok and docker daemon will effectively use the new location for its data.&lt;/p&gt;
&lt;h2 id="5-restart-the-docker-daemon"&gt;5. Restart the docker daemon&lt;/h2&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;sudo service docker start
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;h2 id="6-test"&gt;6. Test&lt;/h2&gt;
&lt;p&gt;If everything is ok you should see no differences in using your docker containers. When you are sure that the new directory is being used correctly by docker daemon you can delete the old data directory.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;code&gt;&lt;span class="n"&gt;sudo&lt;/span&gt; &lt;span class="n"&gt;rm&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;rf&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="k"&gt;var&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;lib&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;docker&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;old&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Follow the previous steps to move docker data directory and you won&amp;#8217;t risk any more to run out of space in your root partition, and you&amp;#8217;ll happily use your docker containers for many years to come. 😉&lt;/p&gt;
&lt;h2 id="7-extra-step-remote-debug-on-your-docker-container"&gt;7. Extra step: remote debug on your Docker container!&lt;/h2&gt;
&lt;p&gt;Do you know that you can remote debug your application running on a Docker container? Check out my tutorial on &lt;a href="https://www.guguweb.com/2020/04/20/remote-debugging-a-django-project-in-vs-code/"&gt;Remote debugging a Django project in VS Code&lt;/a&gt;! It uses Django as an example, but the Docker related part is general.&lt;/p&gt;</content><category term="sysadmin"></category><category term="containers"></category><category term="docker"></category><category term="ubuntu"></category></entry></feed>