First, check the docker location:
docker info
Stop docker service
systemctl stop docker
Look at the high capacity location and create a transfer directory on it
df -h
mkdir -p /home/docker
Take/home/docker as an example. I will transfer the docker of/var/lib/docker to here later.
Migrate the files in/var/lib/docker directory to the target location
sudo rsync -avz /var/lib/docker /home/docker
Create a new/etc/docker/daemon.json file and edit it
There is no such file by default, so you can create and edit it directly with vim
sudo vim /etc/docker/daemon.json
Here is how to use vim.
Press i to enter the insert state and copy the following list into the file
{
"graph":"/docker/lib/docker"
}
Press Esc to exit the insert state, then press shift+:
and then press wq! Enter to force save the file.
PS. If you encounter any swap file already open when inserting, then sudo rm file name to delete the file
Reload docker and restart docker
systemctl daemon-reload && systemctl restart docker
Check whether the docker is changed to a new directory
docker info
Delete old docker directory
rm -rf /var/lib/docker