Skip to content

Instantly share code, notes, and snippets.

@Karreg
Last active October 28, 2020 07:08
Show Gist options
  • Save Karreg/84206b9711cbc6d0fbbe77a57f705979 to your computer and use it in GitHub Desktop.
Save Karreg/84206b9711cbc6d0fbbe77a57f705979 to your computer and use it in GitHub Desktop.
Script to cleanup Docker leftovers, related to https://github.com/moby/moby/issues/22207
#!/bin/bash
echo "WARN: This will remove everything from docker: volumes, containers and images. Will you dare? [y/N] "
read choice
if [ \( "$choice" == "y" \) -o \( "$choice" == "Y" \) ]
then
sudo echo "> sudo rights [OK]"
sizea=`sudo du -sh /var/lib/docker/aufs`
echo "Stopping all running containers"
containers=`docker ps -a -q`
if [ -n "$containers" ]
then
docker stop $containers
fi
echo "Removing all docker images and containers"
docker system prune -f
echo "Stopping Docker daemon"
sudo service docker stop
echo "Removing all leftovers in /var/lib/docker (bug #22207)"
sudo rm -rf /var/lib/docker/aufs
sudo rm -rf /var/lib/docker/image/aufs
sudo rm -f /var/lib/docker/linkgraph.db
echo "Starting Docker daemon"
sudo service docker start
sizeb=`sudo du -sh /var/lib/docker/aufs`
echo "Size before full cleanup:"
echo " $sizea"
echo "Size after full cleanup:"
echo " $sizeb"
fi
@Karreg
Copy link
Author

Karreg commented Sep 6, 2017

You're welcome :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment