NOTE: All of this is done as root and ubuntu 14.04 (may work on other distro's)

  • stop docker: service docker stop
  • get the UUID from our new patition: blkid /dev/vdb1
  • backup your fstab: cp /etc/fstab /etc/fstab.$(date +%Y-%m-%d).bak
  • create the new folder our new disk is going to site on: mkdir /data

  • add this to your /etc/fstab file:

# adding 2nd drive for docker
UUID=9ea9723b-a1a9-4157-84c7-1534a4e886a9 /data           ext4    errors=remount-ro 0       1  
# add a bind mount for /var/lib/docker to /data/docker
/data/docker /var/lib/docker none bind 0 0
  • mount the new drive at /data: mount -a
  • create your new docker folders: mkdir /data/docker
  • copy of the docker stuff to its new location: rsync -aXS /var/lib/docker/. / data/docker/
  • just because I"m paranoid, mv original docker file to backup location (in case the rsync didn't work): mv /var/lib/docker /var/lib/docker.bak
  • remake the docker folder to bind with: mkdir /var/lib/docker
  • compare the data, make sure its the same:
ls /var/lib/docker  
ls /data/docker  
du -sh /var/lib/docker/*  
du -sh /data/docker/*  
  • edit docker config to know where the new location is: nano /etc/default/docker and add DOCKER_OPTS="-g /data/docker"
  • just because I"m paranoid, mv original docker file to backup location (in case the rsync didn't work): mv /var/lib/docker /var/lib/docker.bak
  • start docker backup: service docker start OR reboot for good measure

References