How to verify base device size of docker container

1.5k views Asked by At

I know that Docker uses a storage pool to allocate storage to each container. When using devicemapper storage by default the size of the storage pool is 100GB and the default limit of each container is 10G. This data are shown in Base Device Size and Data Space Total field in docker info.

However, in my scenario docker info do not show these data fields, probably because my storage driver is overlay2 How can I extract this information, is there any other way(s)?

The output of docker info

Containers: 9
  Running: 4
  Paused: 0
  Stopped: 5
Images: 28
Server version: 28
Storage driver: overlay2
  Backing filesystem: extfs
  Supports d_type: true
  Native Overlay diff: true
Logging Driver: json-file
Cgroup Driver: cgroupfs
...

The output of docker version

Docker version 18.09.3, build 774a1fa
2

There are 2 answers

0
BMitch On BEST ANSWER

I know that Docker uses a storage pool to allocate storage to each container.

Nope. Devicemapper uses a storage pool. Most of the other union filesystems work at a file level directly in the parent filesystem. Therefore there is no "base device size" or similar metrics showing preallocated blocks and limits.

You can dig deeper into overlay filesystems to understand how they merge directories from the parent filesystem into a new filesystem that you use inside the container. I have an example of working through the overlay filesystem in my intro presentation here:

https://sudo-bmitch.github.io/presentations/docker-intro/presentation.html#52

And the actual commands used to run that overlay demo are listed in this markdown file.

Therefore, all limits you have with containers using something like the overlay2 filesystem are inherited from the parent filesystem. Since docker does everything under /var/lib/docker, your available disk space on that filesystem are the same as the limits you'll see inside of a container. In my own lab, that's symlinked over to a directory under /home, so you'll see the following on the host and inside the container:

$ ls -l /var/lib/docker
lrwxrwxrwx 1 root root 12 Nov 11  2019 /var/lib/docker -> /home/docker

$ df -h /var/lib/docker/.
Filesystem                         Size  Used Avail Use% Mounted on
/dev/mapper/bmitch--t490--vg-home  857G  355G  459G  44% /home

$ docker run -it --rm busybox df -h /
Filesystem                Size      Used Available Use% Mounted on
overlay                 856.5G    354.6G    458.3G  44% /
0
David Maze On

The "storage pool" and the other metrics you mention are specific to the devicemapper storage driver. The overlay storage driver uses ordinary files and some kernel magic; there isn't any specific space allocation for Docker, and it can use all of the space on the partition mounted on /var/lib/docker.