Docker can take a toll on your disk space.
Fortunately you don’t have to keep the files in /var/lib/docker and on certain cloud providers like Digital Ocean it’s cheaper to attach a new block volume than to upgrade a droplet to get more disk space.
After you’ve decided on a location, simply do:
# systemctl stop docker # mkdir /new/path/docker # rsync -aqxP /var/lib/docker/ /new/path/docker
Change /lib/systemd/system/docker.service:
ExecStart=/usr/bin/dockerd -g /new/path/docker -H fd://
Then:
# systemctl daemon-reload # systemctl start docker
When you’ve verified things are working, remove the old docker directory.
# rm -r /var/lib/docker
Thanks for this post, Piero.
It actually seems that at least in docker release 19.03, the way to go is slightly different (the above method does not work).
Basically:
# edit /etc/docker/daemon.json (if it doesn’t exist, create it) and include:
{
"data-root": "/new/path/to/docker-data"
}
# then restart Docker with:
sudo systemctl daemon-reload
sudo systemctl restart docker
See the third answer at https://stackoverflow.com/questions/24309526/how-to-change-the-docker-image-installation-directory/34731550#34731550,
or this blog post: https://blog.adriel.co.nz/2018/01/25/change-docker-data-directory-in-debian-jessie/.