Migrate Docker Data Directory on CentOS 7

·1 min read·BIGWONG Studio
Docker

When disk space is low, move Docker's data directory from /var/lib/docker to another location.

  1. Back up /var/lib/docker
mv /var/lib/docker /var/lib/dockerbak
  1. Copy data to the new location
cp -rp /var/lib/docker /some-new-dir
  1. Symlink the new directory back
ln -s /some-new-dir/docker /var/lib/docker

Note: After this step, the original directory path becomes the symlink. If you need the original folder again, remove the symlink.

  1. Restart Docker twice (this is how I did it; I no longer remember why)
systemctl restart docker
systemctl restart docker
  1. Verify disk usage
docker ps -s

If everything is fine, you can delete the old backup to save space.