Skip to content

Instantly share code, notes, and snippets.

@ignlg
Created August 5, 2014 07:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ignlg/c1db14cfddef3bda685c to your computer and use it in GitHub Desktop.
Save ignlg/c1db14cfddef3bda685c to your computer and use it in GitHub Desktop.
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