Skip to content

Instantly share code, notes, and snippets.

@spuder
Last active August 29, 2015 14:03
Show Gist options
  • Save spuder/8fe4ca4b0643e800f3ca to your computer and use it in GitHub Desktop.
Save spuder/8fe4ca4b0643e800f3ca to your computer and use it in GitHub Desktop.
Docker Cleanup for mac
# Functions to clean up docker containers on mac
# Based on this blog article, however is more mac friendly (no xargs -r)
# http://blog.stefanxo.com/2014/02/clean-up-after-docker/
# Searches for images and containers that are named/tagged with '<none>' and removes them
# If no results, prints out the usage information
#Create functions since aliases don't play nicely with subshells
dci() {
docker rmi $(docker images --no-trunc | awk '$2 == "<none>" {print $3}')
}
dcc() {
#docker rm $(docker ps -a --no-trunc | awk '$5 == "Exit" {print $1}')
docker ps -a | grep Exit | cut -d ' ' -f 1 | xargs sudo docker rm
}
dce() {
# rm all containers with 'exit' status
docker ps -a | grep Exit | cut -d ' ' -f 1 | xargs docker rm
}
alias dockerclean="dce; dcc; dci"
alias d="docker"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment