By default, the default storage path of the docker image is /var/lib/docker, which is equivalent to directly mounting the root directory. However, if automatic partitioning is selected when installing the system, the root partition is generally not too large, and CentOS will The default is 50G, and Kirin v4 is about 100G.
The default path of docker:
There are three ways to modify the default path of docker
First create a new docker directory
mkdir /home/docker
If centos chooses the default partition during installation, the maximum storage space will be assigned to home, and another disk can also be mounted here, and the new docker directory will be built on the new disk
If the image has been loaded and the container is already running, please stop the docker service first and migrate the data to the new directory
1. Modify docker.service
vim /usr/lib/systemd/system/docker.service
#在里面的EXECStart的后面增加--graph /home/docker:
ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock --graph /home/docker
Execute the following command after saving and exiting
systemctl enable docker
systemctl daemon-reload
systemctl restart docker
2. Edit the configuration file /etc/docker/daemon.json to add "data-root": "/data/docker
vim /etc/docker/daemon.json
{
"registry-mirrors": ["https://registry.docker-cn.com"],
"data-root": "/data/docker"
"log-driver":"json-file",
"log-opts": {"max-size":"100m"}
}
After saving and exiting
Restart the docker application
systemctl restart docker
3. Use soft links
To use soft links, you need to delete the docker directory under /var/lib first, and remember to migrate the data before deleting. Then use the following command to create a soft link
ln -s /home/docker /var/lib
systemctl restart docker
restart docker
The above is the method of modifying the default path of docker, which can be selected according to the actual situation.