docker to modify the storage directory of the mirror container
- 2020-06-15 10:56:22
- OfStack
Recently, I met a problem on my way to learn docker. I looked up 1 piece of information on the Internet and left a note
By default, the default location for Docker images and containers is:
/var/lib/docker
We will not give a large general root under partition. There are two solutions to this problem:
1. Mount the large partition to /var/lib/docker
1 generally choose to establish logical partition lvm to facilitate the later expansion of the collective.
Create a new partition and format it
[root@localhost lib]# lvcreate -L 300G lv_docker vg_home
[root@localhost lib]# mkfs.ext4 /dev/vg_home/lv__docker
Mount the new partition to a temporary hardpoint
[root@localhost lib]# mkdir /mnt/docker
[root@localhost lib]# mount /dev/vg_home/lv_docker /mnt/docker/
After stopping the docker service, copy the data under /var/lib/docker to the temporary mount point
[root@localhost lib]# service docker stop
[root@localhost lib]# cp -r /var/lib/docker/* /mtn/docker
Modify/var/lib/docker/var/lib/docker bak, and create/var/lib/docker
[root@localhost lib]# mv /var/lib/docker{,.bak}
[root@localhost lib]# mkdir /var/lib/docker
Mount the new partition to /var/lib/docker and set the boot mount automatically
[root@localhost lib]# mount /dev/vg_home/lv_docker /var/lib/docker
[root@localhost lib]# vim /etc/fstab
---
/dev/vg_home/lv_docker /var/lib/docker ext4 defaults 0 0
----
Start the Docker service to check that the Docker service is available and that the data is complete
[root@localhost lib]# /etc/init.d/docker start
[root@localhost lib]# docker images
[root@localhost lib]# docker ps -a
After unloading the temporary hardpoints, delete/var lib/docker bak
[root@localhost lib]# umount /mnt/docker
[root@localhost lib]# rm -rf /var/lib/docker.bak
2. Modify the storage path of the image and container
In the Docker service profile
/etc/sysconfig/docker
To modify the parameters of the image and container storage path, add:
other_args="--graph=/data/docker"
Specific steps are as follows:
Discontinue Docker service
[root@localhost lib]# service docker stop
Back up the data to a new storage path
[root@localhost lib]# cp -rf /var/lib/docker /data/
Modify the backup /var/lib/docker path
[root@localhost lib]# mkdir /mnt/docker
[root@localhost lib]# mount /dev/vg_home/lv_docker /mnt/docker/
0
Start the Docker service
[root@localhost lib]# mkdir /mnt/docker
[root@localhost lib]# mount /dev/vg_home/lv_docker /mnt/docker/
1
Test the Docker service
[root@localhost lib]# mkdir /mnt/docker
[root@localhost lib]# mount /dev/vg_home/lv_docker /mnt/docker/
2