Skip to content

Instantly share code, notes, and snippets.

@kirkins
Created July 4, 2017 13:03
Show Gist options
  • Save kirkins/c1f3fecbdd0a58bcc9c645172c3d3236 to your computer and use it in GitHub Desktop.
Save kirkins/c1f3fecbdd0a58bcc9c645172c3d3236 to your computer and use it in GitHub Desktop.
Quick commands for removing docker images and containers
# command to remove all containers and images, with y/N prompt
rmdocker() {
read -r -p "Are you sure you want to remove all docker data? [y/N] " response
case "$response" in
[yY][eE][sS]|[yY])
docker kill $(docker ps -q)
docker rm $(docker ps -a -q)
docker rmi $(docker images -q)
docker volume rm $(docker volume ls -q)
docker network rm $(docker network ls -q)
;;
*)
esac
}
# command to remove all containers but not images
rmcontainers() {
docker kill $(docker ps -q)
docker rm $(docker ps -a -q)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment