docker安装目录迁移

copy from https://gist.github.com/franciscocpg/ac952d1070b16f4f56b3d141e035c9ee

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:
1
sudo systemctl stop docker
  • Create/edit the configuration at /etc/docker/daemon.json, for example:
1
2
3
{
"data-root": "/new/path/docker-data-root"
}
  • Copy your data there:
1
2
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:
1
sudo systemctl start docker
  • Check everything works:
1
docker run hello-world
  • When you ensure that everything is working fine, you can remove data from the old directory:
1
sudo rm -rf /var/lib/docker