Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
@TP75

This comment has been minimized.

TP75 commented Aug 28, 2017

Thank you so much for this excellent script. We are using it now regularily to clean our VMs before installing new docker images. Great help and an almost perfect workaround for the orphaned diffs #22207 issue now. @TP75

@Karreg

This comment has been minimized.

Owner

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