Docker----how to change the storage path of the docker image

【Original link】Docker----how to change the storage path of the docker image

background

With the use of docker container images, docker images take up a lot of disk space. Of course, you can delete images by continuously deleting images or setting up scheduled tasks, but sometimes it is quite troublesome, and in a certain period of time, you may still want to save more Some images are used for backup. If a new disk is added at this time, but the image storage path of the container is not on the mount point of the newly added disk at this time, it is hoped that the storage path of the docker container image can be adjusted and set to For the newly added mount point

Steps

(1) First check the default storage location of the current docker image, as follows

docker info|grep "Docker Root Dir"

In general, if there is no special setting, the default save path is /var/lib/docker

(2) Close all running docker containers

docker ps | awk '{print $1}' |xargs docker stop

(3) Stop the docker service

systemctl stop docker

(4) Create a new directory on the newly added disk mount point, and copy all the original docker containers and images. For example, the mount point of the newly added disk here is /data/, then refer to the following command to operate

mkdir -p /data/var/lib/docker/
cd /data/var/lib/docker/
cp -r /var/lib/docker/* /data/var/lib/docker/

(5) Set the docker configuration file and specify the storage path. If the file does not exist, create one directly

vi /etc/docker/daemon.json

Add the following content

{
    
    
	"data-root": "/data/var/lib/docker",
	"registry-mirrors": ["https://ooe7wn09.mirror.aliyuncs.com"]
	}

(6) Then restart the docker service

systemctl daemon-reload
systemctl start docker

So far, the modification of the default path of the docker container and image has been completed.

Guess you like

Origin blog.csdn.net/redrose2100/article/details/130073174