如何把docker的storage driver改成devicemapper
分两步:
第一步:为VM添加一块disk设备
参考如果给VirtualBox添加设备。
第二步:参考docker文档
https://docs.docker.com/storage/storagedriver/device-mapper-driver/
下面命令内容都是从上述文档链接拷贝下来的。
- Add block device (refer to 第一步)
For exampe /dev/sdb - Stop docker
$ sudo systemctl stop docker
- Create a physical volume on above block device
$ sudo pvcreate /dev/sdb
- Create a docker volume group on above block device
$ sudo vgcreate docker /dev/sdb
- Create two logical volumes named thinpool and thinpoolmeta using the lvcreate command
$ sudo lvcreate --wipesignatures y -n thinpool docker -l 95%VG
$ sudo lvcreate --wipesignatures y -n thinpoolmeta docker -l 1%VG
- Convert the volumes to a thin pool and a storage location for metadata for the thin pool
$ sudo lvconvert -y \
--zero n \
-c 512K \
--thinpool docker/thinpool \
--poolmetadata docker/thinpoolmeta
- Configure autoextension of thin pools
Specify thin_pool_autoextend_threshold and thin_pool_autoextend_percent values.
$ sudo vi /etc/lvm/profile/docker-thinpool.profile
activation {
thin_pool_autoextend_threshold=80
thin_pool_autoextend_percent=20
}
- Apply the LVM profile
$ sudo lvchange --metadataprofile docker-thinpool docker/thinpool
- Enable monitoring for logical volumes on your host.
$ sudo lvs -o+seg_monitor
- Backup /var/lib/docker
$ mkdir /var/lib/docker.bk
$ mv /var/lib/docker/* /var/lib/docker.bk
- Edit /etc/docker/daemon.json and configure the options needed for the devicemapper storage driver.
{
"storage-driver": "devicemapper",
"storage-opts": [
"dm.thinpooldev=/dev/mapper/docker-thinpool",
"dm.use_deferred_removal=true",
"dm.use_deferred_deletion=true"
]
}
- Start docker
$ sudo systemctl start docker
- Verify that Docker is using the new configuration
$ docker info
Containers: 0
Running: 0
Paused: 0
Stopped: 0
Images: 0
Server Version: 17.03.1-ce
Storage Driver: devicemapper
Pool Name: docker-thinpool
...
- Remove backup of /var/lib/docker
$ rm -rf /var/lib/docker.bk