Skip to content

Instantly share code, notes, and snippets.

@mysteriouss
Created February 24, 2022 08:52
Show Gist options
  • Save mysteriouss/d8b8bad7b36b06c24402d0a3f83c300d to your computer and use it in GitHub Desktop.
Save mysteriouss/d8b8bad7b36b06c24402d0a3f83c300d to your computer and use it in GitHub Desktop.
docker container overlay
#!/bin/sh
# grab the size and path to the largest overlay dir
du /var/lib/docker/overlay2 -h | sort -h | tail -n 100 | grep -vE "overlay2$" > /tmp/large-overlay.txt
# make sure json parser is installed
# yum install -y jq
# 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])"' > /tmp/docker-mappings.txt
# for each hashed path, find matching container name
cat /tmp/large-overlay.txt | xargs -l bash -c 'if grep $1 /tmp/docker-mappings.txt; then echo -n "$0 "; fi'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment