Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Docker cleanup script: Removes all the containers (error for running ones) and all the unnamed (<none>) images (error for images attached to a running container)
#!/bin/bash
###
# Docker cleanup script
#
# Cleans all the containers (error for running ones) and all the
# unnamed images (error for images attached to a running container)
#
#
# LICENSE:
#
# DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
# Version 2, December 2004
#
# Copyright (C) 2014 Ignacio Lago <ignacio@ignaciolago.com>
#
# Everyone is permitted to copy and distribute verbatim or modified
# copies of this license document, and changing it is allowed as long
# as the name is changed.
#
# DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
# TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
#
# 0. You just DO WHAT THE FUCK YOU WANT TO.
#
###
## Clean containers
docker ps -aq | xargs docker rm
## Clean unnamed images
docker images | grep "^<none>" | awk '{print $3}' | xargs docker rmi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment