Docker Disk Usage Exceeds Disk Capacity

Hello guys, I am so confused by the disk usage issue.

Here I use docker system df to show the amount of disk space used by the docker, and you can see that docker only uses 6.2GB disk space:

Images          1         0         6.21GB    6.21GB (100%)
Containers      0         0         0B        0B
Local Volumes   0         0         0B        0B
Build Cache     0         0         0B        0B

But when I use sudo btrfs filesystem du -s /var/lib/docker/ to show the disk usage, I get the following result:

     Total   Exclusive  Set shared  Filename
 127.16GiB    52.29MiB     5.77GiB  /var/lib/docker/

And this 127.16GB actually exceeds my disk capacity allocated for openSUSE, which is 75GB. And the result of sudo btrfs filesystem show is as follows:

Label: 'openSUSE'  uuid: bb51d104-2db0-4965-8f2a-057d8f684dab
        Total devices 1 FS bytes used 22.30GiB
        devid    1 size 75.00GiB used 30.07GiB path /dev/nvme0n1p5

Label: none  uuid: 76ba0f42-c83c-4b7a-9797-c040abbd458b
        Total devices 1 FS bytes used 15.66GiB
        devid    1 size 96.00GiB used 18.02GiB path /dev/nvme1n1p2

But my system does not crash and can be normally used. So what is going wrong here? What is actually disk usage?

My environment:

system info
 Context:    default
 Debug Mode: false

 Containers: 0
  Running: 0
  Paused: 0
  Stopped: 0
 Images: 1
 Server Version: 20.10.23-ce
 Storage Driver: btrfs
  Build Version: Btrfs v6.1.3
  Library Version: 102
 Logging Driver: json-file
 Cgroup Driver: systemd
 Cgroup Version: 2
  Volume: local
  Network: bridge host ipvlan macvlan null overlay
  Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
 Swarm: inactive
 Runtimes: io.containerd.runc.v2 io.containerd.runtime.v1.linux nvidia oci runc
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: 31aa4358a36870b21a992d3ad2bef29e1d693bec
 runc version: v1.1.4-0-ga916309fff0f
 init version:
 Security Options:
   Profile: default
 Kernel Version: 6.2.4-1-default
 Operating System: openSUSE Tumbleweed
 OSType: linux
 Architecture: x86_64
 CPUs: 12
 Total Memory: 30.96GiB
 Name: az-P1-openSUSE
 Docker Root Dir: /var/lib/docker
 Debug Mode: false
 Experimental: false
 Insecure Registries:
 Live Restore Enabled: false

I don’t know how btrfs works exactly but the content of /var/lib/docker contains a lot of special files, references, mounts and it could change the result when you try to get the size using “du”. If btrfs filesystem du works the same way that can be the cause of the result.

For example in case of overlay2 storage driver you will find the folders of the image layer files under /var/lib/docker/overlay2, but you you will also find the MergedDir of each container which is just some image layer folders and a writable container layer folder mounted on top of eachother.

If you want to see a better result, you need to use the -x flag of du which is the alias of --one-file-system.

du -sx /var/lib/docker

Now you need to translate it to the btrfs command if it uses different parameters.

1 Like