Disk Spacee Analysis
When disk usage approaches critical levels, begin by examining storage utilization with the df -h command:
[root@docker ~]# df -h
Filesystem Size Used Avail Use% Mounted on
devtmpfs 937M 0 937M 0% /dev
tmpfs 949M 0 949M 0% /dev/shm
tmpfs 949M 520K 948M 1% /run
tmpfs 949M 0 949M 0% /sys/fs/cgroup
/dev/vda1 50G 48G 2G 98% /
/dev/vdb1 985G 565G 420G 57% /
overlay 50G 48G 2G 98% /var/lib/docker/overlay2/merged
tmpfs 190M 0 190M 0% /run/user/0
The overlay filesystem represents Docker's storage driver, with actual data residing on /dev/vda1. Primary causes for excessive disk consumption include:
- Accumulated unused images and containers
- Unmanaged container log files
Cleaning Unused Docker Resources
Assess storage allocation across Docker components:
docker system df -v
Remove all unused images, containers, volumes, and networks:
docker system prune -a
Manaigng Container Logs
Container logs accumulate in /var/lib/docker/containers/{containerId}/. Identify large log files:
cd /var/lib/docker/containers/
du -h --max-depth=1
Sample output showing a large log file:
356K ./container_short_id1
542M ./container_short_id2
20G ./container_short_id3
Navigate to the problematic container directory and check log size:
cd container_short_id3
du -sh *-json.log
Implementing Log Rotation
Configure Docker daemon log management in /etc/docker/daemon.json:
{
"log-driver": "json-file",
"log-opts": {
"max-size": "100m",
"max-file": "3"
}
}
This configuraton limits individual log files to 100MB while retaining up to 3 rotated files. Apply changes:
systemctl restart docker
Immediate Log Cleanup
For immediate space recovery, truncate existing log files:
cat /dev/null > container_id-json.log