Take note that you can use this approach to move the /var/lib/docker
directory to another disk or partition.
Just make sure you create the destination directory in this new disk or partition.
- 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 mkdir /new/path/
sudo rsync -avxP /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:
docker run hello-world
- When you ensure that everything is working fine, you can remove data from the old directory:
sudo rm -rf /var/lib/docker