Pippo's blog

it is all about software development

Easy docker clean

UPDATE: small improvements done to the function incorporated here: 2015-09-07

Working a lot with docker recently and I Love it. Problem was keeping it from burning my hard drive with lots of images and containers files.

After a few rounds and tunning a script to clean the mess, this is what is working best for me, thought it could help more people:

1
2
3
4
5
6
7
docker_clean ()
{
    local zombie_containers=$(docker ps -a -q | grep -v "$(docker ps -q | xargs | sed 's/ /\\\|/g') ");
    local zombie_images=$(docker images --no-trunc | grep none | awk '{print $3 }');
    docker rm -v ${zombie_containers} 2> /dev/null;
    docker rmi ${zombie_images} 2> /dev/null
}

Enjoy!

Comments