My project will run clients' (docker) containers with kubernetes. And the command df -h
inside docker container will show the host /
usage like this:
root@aggregator-demo-vgpovusabzqf-578f547cc5-rc8g6:/# df -h
Filesystem Size Used Avail Use% Mounted on
overlay 1.8T 227G 1.5T 14% /
tmpfs 64M 0 64M 0% /dev
tmpfs 252G 0 252G 0% /sys/fs/cgroup
/dev/mapper/ubuntu--vg-ubuntu--lv 1.8T 227G 1.5T 14% /etc/hosts
shm 64M 0 64M 0% /dev/shm
tmpfs 504G 12K 504G 1% /run/secrets/kubernetes.io/serviceaccount
tmpfs 252G 0 252G 0% /proc/acpi
tmpfs 252G 0 252G 0% /proc/scsi
tmpfs 252G 0 252G 0% /sys/firmware
which is not quite helpful for user to understand how much storage already used. And I see some container platforms which can show only the actually user usage like this:
root@container-bc574b56:~# df -lh
Filesystem Size Used Avail Use% Mounted on
overlay 25G 574M 25G 3% /
tmpfs 64M 0 64M 0% /dev
tmpfs 378G 0 378G 0% /sys/fs/cgroup
shm 40G 0 40G 0% /dev/shm
/dev/sdb 150M 4.0K 150M 1% /init
tmpfs 378G 12K 378G 1% /proc/driver/nvidia
/dev/sda2 219G 26G 184G 13% /usr/bin/nvidia-smi
udev 378G 0 378G 0% /dev/nvidiactl
tmpfs 378G 0 378G 0% /proc/asound
tmpfs 378G 0 378G 0% /proc/acpi
tmpfs 378G 0 378G 0% /proc/scsi
tmpfs 378G 0 378G 0% /sys/firmware
The /
directory shows Avail
is 25Gi
which is the actual container limitation and the Used
is 574M
which is the docker upper directory usage. How to implement like this? Maybe this is not the capability of docker and it may use some other implementation?
CodePudding user response:
df
simply queries the filesystem for available space.
If you're using the standard overlay2
driver, the container filesystem is just a view onto the host filesystem; there's no way for df
to provide a container specific value because there is no separate filesystem.
If you're using something like the devicemapper
, zfs
, or btrfs
storage drivers, then each container has its own unique filesystem, so df
can provide information that is specific to the container.