1.创建一个虚拟快设备
dd if=/dev/zero of=4G.img bs=1M count=4096
2.创建loop device
可以先用losetup -f 查看空闲的loop设备
losetup /dev/loop0 /datac/docker/4G.img
3. 创建PV,VG
pvcreate /dev/loop0
vgcreate docker /dev/loop0
4. 创建thinpool
lvcreate --wipesignatures y -n thinpool docker -l 95%VG
lvcreate --wipesignatures y -n thinpoolmeta docker -l 1%VG
lvconvert -y --zero n -c 512K --thinpool docker/thinpool --poolmetadata docker/thinpoolmeta
5.配置
vi /etc/lvm/profile/docker-thinpool.profile
activation { thin_pool_autoextend_threshold=80 thin_pool_autoextend_percent=20 }
lvchange --metadataprofile docker-thinpool docker/thinpool
6.修改docker配置
/etc/docker/daemon.json
"storage-driver": "devicemapper",
"storage-opts": [
"dm.thinpooldev=/dev/mapper/docker-thinpool",
"dm.use_deferred_removal=true",
"dm.use_deferred_deletion=true"
]
or
--storage-driver=devicemapper --storage-opt=dm.thinpooldev=/dev/mapper/docker-thinpool --storage-opt dm.use_deferred_removal=true
参考文档
https://docs.docker.com/engine/userguide/storagedriver/device-mapper-driver/