By default docker will put all the data including images under /var/lib/docker
(At least on Debian Linux). This could lead to problems with space your machine. Its was case now on my home server, so I had to move the docker location. I had to mount /var/lib/docker
to new place. Because my /var
and /usr
are mounted to different partitions and discs, I try to solve the space problem by mounting docker default location to the new mount under /usr/local/docker
transparently.
At first, do backup of the /etc/fstab
sudo cp /etc/fstab /etc/fstab.$(date +%Y-%m-%d)
Then stop docker daemon and copy all files per rsync
preserving all file attributes.
sudo service docker stop
sudo mkdir /usr/local/docker
sudo rsync -aXS /var/lib/docker/. /usr/local/docker/
Now it was important to check that everything was copied right. I’ve done an eye check, but diff -r
command is useful too. Ok, it’s important to make a new mount and make it durable in fstab
. That is what was useful in my case inside of fstab.
# <file> <system> <mount point> <type> <options> <dump> <pass>
# ...
/usr/local/docker /var/lib/docker none bind 0 0
Now mount the new configuration without a reboot.
mount -a
And your docker has enough space again!