docker modify the storage path of the image and the container (the latest practice of the third method)

Original: docker Modify the storage path of the image and the container (latest practice the third method)

docker info: View related information such as docker storage.

Modify the path to the mounted disk

Prerequisite: The disk has been mounted successfully

method one:

1. Stop the docker service

service docker stop

2. Back up data to a new storage path

cp -r /var/lib/docker/* /mnt/docker

3. Backup / var / lib / docker path

mv /var/lib/docker  /var/lib/dockerbak}

4. Create a soft connection

ln -s /mnt/docker /var/lib/docker

5. Start docker

service docker start

If docker is complete and available, you can delete the original backup file

This method, when starting Docker, found that the storage directory is still / var / lib / docker, but it is actually stored in the data disk. You can see the capacity change on the data disk.

 

Method Two:

Close docker

Position in Ubuntu is: /etc/default/dockerthe position in CentOS are: /etc/sysconfig/docker.

Add the following code to OPTIONS: --graph = / local / docker new storage directory

OPTIONS='--selinux-enabled --log-driver=journald --signature-verification=false --graph=/local/docker --insecure-registry=0.0.0.0/0'

After restarting docker, docker info can see the directory changed

 

Method 3: (Recommendation: After installing docker, modify the default path in time. Do not wait until the application-level image pull comes in and then modify the default storage path, otherwise you will be overwhelmed by various errors.

It is best to close docker first

If docker is version 1.12 or above, you can modify (or create a new) daemon.json file. The modification will take effect immediately without restarting the docker service.

vim /etc/docker/daemon.json 

{

"graph": "/new-path/docker"

}

Note: If there is an image and corresponding data before, after performing this step, the default storage path is changed, but it will cause the previous image cannot be found. R to the directory where the data partition is mounted: cp -R / var / lib / docker / * / data / tootls / docker /

Then test whether the image can be found

Guess you like

Origin www.cnblogs.com/lonelyxmas/p/12690402.html