Technotes

Technotes for future me

Docker: determining container responsible for largest overlay directories

# as root
sudo su

# grab the size and path to the largest overlay dir
du /var/lib/docker/overlay2 -h | sort -h | tail -n 100 | grep -vE "overlay2$" > large-overlay.txt

# make sure json parser is installed 
apt-get install jq -y 

# construct mappings of name to hash
docker inspect $(docker ps -qa) | jq -r 'map([.Name, .GraphDriver.Data.MergedDir]) | .[] | "\(.[0])\t\(.[1])"' > docker-mappings.txt

# for each hashed path, find matching container name
cat large-overlay.txt | xargs -l bash -c 'if grep $1 docker-mappings.txt; then echo -e "$0 \n"; fi'

source:
https://fabianlee.org/2021/04/08/docker-determining-container-responsible-for-largest-overlay-directories/

Last updated on 5 Jul 2022
Published on 14 Dec 2019
Edit on GitHub