How to find docker storage device and its size (device mapper storage driver)

Question: How to find the running docker storage device when docker is using the device-mapper storage driver and then check the size of it?

1. Please run the “docker info” command to display docker system-wide information which contains the docker storage info.

# docker info

Containers: 0
Running: 0
Paused: 0
Stopped: 0
Images: 0
Server Version: 18.03.1-ol
Storage Driver: devicemapper
Pool Name: docker-251:0-102683530-pool
Pool Blocksize: 65.54kB
Base Device Size: 26.84GB
Backing Filesystem: xfs
Udev Sync Supported: true
Data file: /dev/loop0   data file
Metadata file: /dev/loop1      metadata file
Data loop file: /var/lib/docker/devicemapper/devicemapper/data      data file
Metadata loop file: /var/lib/docker/devicemapper/devicemapper/metadata        metadata file
Data Space Used: 14.42MB        used space of data file
Data Space Total: 107.4GB       total space of data file
Data Space Available: 14.71GB 
Metadata Space Used: 581.6kB        used space of metadata file
Metadata Space Total: 2.147GB       total space of metadata file
Metadata Space Available: 2.147GB
Thin Pool Minimum Free Space: 10.74GB
Deferred Removal Enabled: true
Deferred Deletion Enabled: true
Deferred Deleted Device Count: 0
Library Version: 1.02.135-RHEL7 (2016-09-28)
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins:
Volume: local
Network: bridge host macvlan null overlay
Log: awslogs fluentd gcplogs gelf journald json-file logentries splunk syslog
Swarm: inactive
Runtimes: runc
Default Runtime: run
...

2. We can also use “lsblk” and “blkid” to check the layout and UUID of the docker storage.

# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 20G 0 disk
├─sda1 8:1 0 1G 0 part /boot
└─sda2 8:2 0 19G 0 part
├─ol-root 251:0 0 17G 0 lvm /
└─ol-swap 251:1 0 2G 0 lvm [SWAP]
sr0 11:0 1 1024M 0 rom
sr1 11:1 1 1024M 0 rom
loop0 7:0 0 100G 0 loop
└─docker-251:0-102683530-pool 251:2 0 100G 0 dm
loop1 7:1 0 2G 0 loop
└─docker-251:0-102683530-pool 251:2 0 100G 0 dm
# blkid
...
/dev/loop0: UUID="19e56ade-5aeb-476f-aa95-ce68ec99b17a" TYPE="xfs"
/dev/mapper/docker-251:0-102683530-pool: UUID="19e56ade-5aeb-476f-aa95-ce68ec99b17a" TYPE="xfs"

3. We can find the actual loopback-mounted sparse files on the file system.

# ll /var/lib/docker/devicemapper/devicemapper -l
total 13904
-rw-------. 1 root root 107374182400 Jan 7 09:47 data     100 GB displayed size
-rw-------. 1 root root 2147483648 Jan 7 10:48 metadata    2 GB displayed size
# du -skh *
13M data      13MB actual size
600K metadata        600 KB actual size

4. We can also use “losetup” to query the mapping of the loop devices for docker storage.

# losetup -a
/dev/loop0: [64256]:33600329 (/var/lib/docker/devicemapper/devicemapper/data)
/dev/loop1: [64256]:33600330 (/var/lib/docker/devicemapper/devicemapper/metadata)

Hence, from the above output, we can find that the docker storage is running in loop mode. This is indicated by the fact that the data loop file and a metadata loop file are on files under /var/lib/docker/devicemapper. These are loopback-mounted sparse files. Therefore the size of these displayed sparse files is much bigger than their actual size on the disk.

Related Post