Move Docker directory to a different partition

01 January 2015
I frequently use Docker for all kinds of tasks. I especially like it to build projects or OpenWrt images to keep my system clean from dozens of build dependencies. Unfortunately, over time, this bloats my root partition quite a lot.

I figured out, that Docker stores all the image and container data in /var/lib/docker. So, this problem should be solvable using bind mount.

First, make sure your docker daemon is not running and create a new directory on another partition which has plenty of space left:

mkdir /path/to/newdir

Then move all the files and directories from /var/lib/docker to your new directory:

mv /var/lib/docker /path/to/newdir

Finally, mount your new directory on top of /var/lib/docker:

mounti -o bind /var/lib/docker /path/to/newdir

In order to make this persistent across reboots, append the following line to your /etc/fstab:

/var/lib/docker /path/to/newdir none bind 0 0

There should be plenty of space now on /. :)