Docker storage configuration for Devicemapper + DIRECT_LVM in Centos-7 + Docker-1.12

Source: Internet
Author: User
Tags docker run

Application background:Docker is the first to run on Ubuntu and Debian, using AUFS memory. Because Docker is becoming more popular, many companies want to use it on Rhel, but the upstream kernel does not include AUFS, so Rhel cannot use Aufs. Eventually, developers developed a new back-end storage engine Devicemapper, based on existing device mapper technology, and made Docker support pluggable, and now there are many real-world cases in use devicemapper in production environments. For these reasons, for systems with no related drivers such as Centos/rhel, it is common to use the Devicemapper driver to simulate tiered storage using some of the mechanisms of LVM. This approach, in addition to poor performance, stability is generally not good, and the configuration is relatively complex. When Docker is installed on Centos/rhel, Devicemapper is selected by default, but in order to simplify the configuration, its devicemapper is to run on a block device of a sparse file emulation, also known as LOOP-LVM. The option is to run Docker without the need for additional configuration, which is the only thing that can be done with automatic configuration. But LOOP-LVM's approach is very bad, its stability, performance is worse, both in the log or Docker info will see a warning message. The official documentation has a clear article on how to configure a block device to give the Devicemapper driver a storage layer approach, which is also known as configuration DIRECT-LVM. In addition to the previously mentioned problem, Devicemapper + LOOP-LVM has a flaw because it is a sparse file, so it will grow continuously. Users will notice that the/var/lib/docker/devicemapper/devicemapper/data is growing and beyond control during their use. Many people will want to remove the image or solve the problem, and the results are not obvious. The reason is that the sparse file space is not garbage collected after the release of the basic problem. As a result, even if the contents of the file are deleted, the space is not recycled, and the sparse file continues to grow as it is used.So,for Centos/rhel users, in the absence of a way to use UnionFS, be sure to configure DIRECT-LVM to Devicemapper, whether for performance, stability or space utilization . Configure the Environment:CentOS 7docker 1.12 Configuration steps: 1. Stop docker Daemon (root)#>Systemctl Stop Docker 2. Creating related logical volumes and thinpool (root)(1). Allocate disk allocation disk to the server and use Fdisk for partitioning. (2). Create PV For example: Assigned disk/dev/sdb1#>PVCREATE/DEV/SDB1(3). Create vg#>vgcreate dockervg/dev/sdb1(4). Create a thinpool logical volume #>lvcreate--wipesignatures y-n thinpool-l 50%vg dockervglvcreate--wipesignatures y-n thinpoolmeta-l 1%vg dockervgThe following command can be used to verify#> Lvscan (5). Convert to Thinpool
#> lvconvert-y--zero n-c 512K--thinpool dockervg/thinpool--poolmetadata dockervg/thinpoolmeta The output results are similar to the following. You can view the Thinpool status by using the following command #>Lvs-o lv_name,data_percent,metadata_percent,lv_size,lv_metadata_size,data_lv,metadata_lvThe output results are similar to the following. Note:which lsizeThat is, the space size of Data, msizeThat is, the size of the MetaData space, DataCorresponds to the logical volume for Data, MetaCorresponds to a logical volume for MetaData. (6). Extended Thinpool (optional) This step is chosen for the expansion of MetaData or Data when the space is insufficient. For example: MetaData corresponds to a logical volume path of/dev/mapper/dockervg-thinpool_tmeta, the expansion command is as follows. #>lvresize-l +1g/dev/mapper/dockervg-thinpool_tmetaFor example: Thinpool the overall corresponding logical volume path is dockervg-thinpool, the expansion command is as follows. #>lvresize-l +5g/dev/mapper/dockervg-thinpool 3. Backup and delete Docker storage directory (root)(1). Backup #>MKDIR/VAR/LIB/DOCKER.BKmv/var/lib/docker/*/VAR/LIB/DOCKER.BK(2). Delete the original storage directory #>rm-rf/var/lib/docker/* 4. Modify Docker boot parameters and start (root)

Modifying the Daemon.json configuration file
#>Vi/etc/docker/daemon.json
Modify to the following content.
{
" storage-driver": "Devicemapper",
"storage-opts": [
"Dm.thinpooldev=/dev/mapper/dockervg-thinpool",
"Dm.use_deferred_removal=true",
"Dm.use_deferred_deletion=true",

"dm.basesize=25g"
   ]
} Note:DM.BASESIZE specifies the images and container that can be extended to the Maximum Space
5. Restart Docker Service (root)#>Systemctl daemon-reloadSystemctl start Docker 6. Authentication (root)
A.docker Info Check#> Docker InfoThe results are similar to the following. The information in the box indicates that the DIRECT_LVM Docker storage mode is used, while images and container can be extended to the The maximum space has been modified to the desired size. B. Trial run Hello-world#> Docker Pull Hello-world Docker Run Hello-worldThe result is similar to the following, which indicates normal operation.

References:https://docs.docker.com/engine/userguide/storagedriver/device-mapper-driver/#configure-direct-lvm-mode-for-production

Docker storage configuration for Devicemapper + DIRECT_LVM in Centos-7 + Docker-1.12

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.