By Bobby Iliev
I recently had a case where the /
partition was running very low on disk space, but I also had an additional disk mounted at /home/
with plenty of disk space.
However as by default Docker stores everything at /var/lib/docker
my /
partition was nearly full.
To fix that I moved the default /var/lib/docker
to another directory on the /home
partition.
In case that you are in the same situation, here is how to do that on a Linux server!
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
Accepted Answer
Before you get started, make sure to backup your Droplet so that in case that anything goes wrong, you could revert back to a backup!
Once you have your backup in place, follow these steps here:
Make sure that Docker is stopped:
- sudo systemctl stop docker
After that, make sure that Docker is not running with the following commands:
- sudo systemctl status docker
If you see that Docker is not running, then you could proceed. Another way of checking if there are any Docker processes is by using the ps
command:
- ps faux | grep -i docker
/var/lib/docker/
Docker directory to the new location. Let’s say that we want to put the files in a folder called /home/docker
. To do so, first create the folder:- mkdir /home/docker
Then using the rsync
command transfer the files over:
- rsync -avxP /var/lib/docker/ /home/docker
Note: this might take a while depending on the size of your images. If your folder is too large you might want to run the rsync command in a screen session to avoid your connection being dropped and interrupting the transfer.
- sudo nano /lib/systemd/system/docker.service
Find the following line:
ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
And change it to:
ExecStart=/usr/bin/dockerd -g /home/docker -H fd:// --containerd=/run/containerd/containerd.sock
Then reload the systemd daemons:
- sudo systemctl daemon-reload
And finally, start Docker:
- systemctl start docker
Finally, to confirm if your images are being loaded from the new path, you can inspect one of your images:
Find an image id:
docker images
Inspect the image and look for the WorkDir:
docker inspect image_id | grep WorkDir
I hope that this helps! Regards, Bobby
sudo systemctl stop docker
/etc/docker/daemon.json
, for example:{
"data-root": "/new/path/docker-data-root"
}
sudo cp -axT /var/lib/docker /new/path/docker-data-root
(if the target docker-data-root
directory already exists, make sure you don’t accidentally copy into a docker
subdirectory).
sudo systemctl start docker
sudo docker images
The previous answer:
-g
. Instead you should use the option documented in dockerd --help
, which is --data-root
.Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.