[Docker] docker | migrate docker directory

1. Scenario description

1. The disk space of the physical machine is not enough.
2. The default path of docker images, containers, volumes and other data is: /var/lib/docker
3. The data disk is added, and all docker data needs to be replaced with a directory

2. Operation

  1. Confirm whether the switching conditions are met

1) Whether the service can be suspended, if so, OK
2) The core data conditions can be backed up, the service can be suspended, and the data cannot be lost
  1. Confirm docker status

systemctl status docker
  1. stop docker

systemctl stop docker
  1. docker migration

rsync -r -avz /var/lib/docker /mnt/data/data131/docker
1) Data disk mapping relationship: 
nas disk: {nas.ip}:/mnt/data/data131/docker
physical machine: /mnt/data/data131/docker
2) Time-consuming, too much data in images, containers, and volumes
  1. Backup docker original soft route

mv /var/lib/docker /var/lib/docker-old
  1. Create a new soft route

ln -s /mnt/data/data131/docker /var/lib/docker
  1. start docker

systemctl start docker
  1. View docker status

systemctl status docker
1) If it is normal, it is OK
  1. View docker disk usage

docker system df
1) At this point, ok
2) After 10, it is the verification process
  1. create volume

docker volume create uptime-kuma
  1. View volume location

cd /mnt/data/data131/docker/volumns
ll
1) The volume creation is ok, and the location is correct
2) The operation is very smooth, and I wish the same
3) I found that during the migration process, there is no need to stop the container; and docker ps found that it still runs again; it is almost 6

Guess you like

Origin blog.csdn.net/myloverisxin/article/details/129321519