Skip to content

Instantly share code, notes, and snippets.

@Najki
Created May 8, 2018 10:05
Show Gist options
  • Save Najki/9e268bc8fc18633ccef1123c36133868 to your computer and use it in GitHub Desktop.
Save Najki/9e268bc8fc18633ccef1123c36133868 to your computer and use it in GitHub Desktop.
Call fstrim for Docker virtual disk
#!/bin/bash
# Credits for the idea to https://djs55.github.io/jekyll/update/2017/11/27/docker-for-mac-disk-space.html
get_size () {
ls -alks $HOME/Library/Containers/com.docker.docker/Data/com.docker.driver.amd64-linux/Docker.raw | awk '{print $1}'
}
reclaim_space () {
docker run --rm -it --privileged --pid=host walkerlee/nsenter -t 1 -m -u -i -n fstrim /var/lib/docker
}
BEFORE=$(get_size)
echo "Before: $BEFORE bytes"
echo "Running fstrim on /var/lib/docker..."
reclaim_space
AFTER=$(get_size)
echo "After: $AFTER bytes"
RECLAIMED=$(($BEFORE - $AFTER))
echo "Reclaimed space: $RECLAIMED bytes"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment