Where should I store my Docker images?

In RHEl 7 or CentOS 7, the default Docker configuration uses devicemapper with loopback. This works perfect for testing or in a development environment...it's a bad idea for production.

Note: RHEL/CentOS Atomic Hosts are pre-configured for dedicated pools.


Edit the /etc/sysconfig/docker-storage-setup.

# vi /etc/sysconfig/docker-storage-setup

Add the following parameters to the /etc/sysconfig/docker-storage-setup file.


Stop Docker.

# systemctl stop docker

Remove any existing docker storage configuration file.

# rm -f /etc/sysconfig/docker-storage

Remove existing Docker location.

 # rm -f /var/lib/docker

Create a physical volume--in this example, /dev/sdd (and it is 20GB). Use the pvs and/or the fdisk -l command to verify you are working with the correct device/disk.

# pvcreate /dev/sdd

Create a volume group (i.e. dockervg). Volume group name must be the same name you specified in the /etc/sysconfig/docker-storage-setup file under the VG parameter.

# vgcreate dockervg /dev/sdd

Run the docker-storage-setup configuration tool.

# /bin/docker-storage-setup

Run the lvs command to check things out.

# lvs
LV          VG       Attr       LSize  Pool Origin Data%  Meta%  Move Log Cpy%Sync
docker-pool dockervg twi-a-t---  8.00g             0.00   0.16   

Now we have a 8GB LVM thinpool for our Docker images. Wait...I thought the disk was 20GB.

Let's extend it. Run the vgdisplay command to check how much space is left in the volume group. In my case...3059 Extents are free

# vgdisplay dockervg
  --- Volume group ---
  Free  PE / Size       3059 / 12.00 GB

Now extend.

lvextend -l +3059 /dev/dockervg/docker-pool

Run the lvs command again.

# lvs
LV          VG       Attr       LSize  Pool Origin Data%  Meta%  Move Log Cpy%Sync
docker-pool dockervg twi-a-t--- 19.95g             0.16   0.24 

Much better.

Crank Docker back up.

# systemctl start docker

Finally, verify.

# docker info
Storage Driver: devicemapper
Pool Name: dockervg-docker--pool
Pool Blocksize: 524.3 kB
Base Device Size: 10.74 GB
Backing Filesystem: xfs
Data file: 
Metadata file: 
Data Space Used: 34.6 MB
Data Space Total: 21.42 GB
Data Space Available: 21.39 GB
Metadata Space Used: 61.44 kB
Metadata Space Total: 25.17 MB
Metadata Space Available: 25.1 MB
Thin Pool Minimum Free Space: 2.142 GB
Udev Sync Supported: true
Deferred Removal Enabled: true
Deferred Deletion Enabled: false
Deferred Deleted Device Count: 0
Library Version: 1.02.135-RHEL7 (2016-11-16)

Naturally, you will want to keep your LVM thinpool "lean and clean". Check out How to delete unused Docker images for more details.