Stop the server:
sudo systemctl stop docker
Create/edit the configuration at /etc/docker/daemon.json, for example:
{
"data-root": "/new/path/docker-data-root"
}
Copy your data there:
sudo cp -axT /var/lib/docker /new/path/docker-data-root
(if the target docker-data-root directory already exists, make sure you don’t accidentally copy into a docker subdirectory).
Start the server:
sudo systemctl start docker
Check everything works:
sudo docker images
The previous answer:
Uses an obsolete/undocumented(?) option -g. Instead you should use the option documented in dockerd --help, which is --data-root.
Edits the service file, which might cause problems when installing updates. Instead you should edit /etc/docker/daemon.json.
Uses rsync to copy files without preserving ACLs, xattrs and hard links, though I’m not sure there’s any.