如何把docker的storage driver改成devicemapper

如何把docker的storage driver改成devicemapper

分两步:

第一步:为VM添加一块disk设备

参考如果给VirtualBox添加设备。

第二步:参考docker文档

https://docs.docker.com/storage/storagedriver/device-mapper-driver/

下面命令内容都是从上述文档链接拷贝下来的。

  1. Add block device (refer to 第一步)
    For exampe /dev/sdb
  2. Stop docker
$ sudo systemctl stop docker
  1. Create a physical volume on above block device
$ sudo pvcreate /dev/sdb
  1. Create a docker volume group on above block device
$ sudo vgcreate docker /dev/sdb
  1. 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
  1. 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
  1. 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
}
  1. Apply the LVM profile
$ sudo lvchange --metadataprofile docker-thinpool docker/thinpool
  1. Enable monitoring for logical volumes on your host.
$ sudo lvs -o+seg_monitor
  1. Backup /var/lib/docker
$ mkdir /var/lib/docker.bk
$ mv /var/lib/docker/* /var/lib/docker.bk
  1. 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"
    ]
}
  1. Start docker
$ sudo systemctl start docker
  1. 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
...
  1. Remove backup of /var/lib/docker
$ rm -rf /var/lib/docker.bk

你可能感兴趣的:(如何把docker的storage driver改成devicemapper)