OwnBlog from DimiG    About    Archive    RSS

Docker and CentOS 7 (Part II)

The second part of article Docker and CentOS 7 will highlight the question about Docker optimization for CentOS production platform. Here is how.

By default the CentOS 7 installer will create the XFS file system during OS installation. The XFS file systems must be created with the -n ftype=1 option enabled for use as an overlay. If no there is a problem cause to change it you have to reformat the file system with correct settings. The newer CentOS installers do it with ftype=1 option enabled.

To check the settings on your file system is possible do by:

$ xfs_info /

If you get something like this:

naming =version 2 bsize=4096 ascii-ci=0 ftype=0

You have a problem with docker installation.

Also Docker may inform you about by this command:

$ docker info

There are different ways to overcome this problem. Format the main disk wasn’t option for me. My way was to create thinpool as a part of LVM on other hard drive. Also it is a recommended way to use Docker with production servers to achieve better speed. Lets have a look how.

I have created the thinpool partition on separate hard drive. All manipulations MUST be issued by root. So, be careful with your data. Backup important data first.

  • First of all - stop Docker:
[root@host ~]# systemctl stop docker
  • Format the partition (you can use cfdisk or fdisk what you prefer):
[root@host ~]# cfdisk /dev/sda3

Be careful with formatting! You may damage your data!
*NOTE: Your paths may be different on your system!

  • Lets show to kernel some changes by this:
[root@host ~]# partprobe
  • Create the Physical Volume by:
[root@host ~]# pvcreate /dev/sda3
  • Create the Volume Group by:
[root@host ~]# vgcreate -s 32M vg_docker /dev/sda3
  • Check Volume Group if everything correct by:
[root@host ~]# vgs
  • Create a Logical Volume by:
[root@host ~]# lvcreate -L 20G --thinpool tp_docker_pool vg_docker
  • Check Logical Volume if everything correct by:
[root@host ~]# lvs
[root@host ~]# lvdisplay vg_docker/tp_docker_pool

The next step is change the Docker configuration.

  • I have removed the Docker files by this:
[root@host ~]# rm -rf /var/lib/docker/*
  • Next, create the daemon.json file by this PATH:
[root@host ~]# touch /etc/docker/daemon.json
  • With such text inside:
{
 "storage-driver": "devicemapper",
 "storage-opts": [
        "dm.thinpooldev=/dev/mapper/vg_docker-tp_docker_pool",
        "dm.use_deferred_removal=true"
 ]
}
  • After that start Docker again:
[root@host ~]# systemctl start docker
  • Now Docker should work without any warnings. Check it by:
[root@host ~]# docker info
  • To test if Docker still running use:
[root@host ~]# docker run --rm hello-world

If you see Hello World you passed this quest ;)

Be back soon. Thanks for your time…