Skip to content

Instantly share code, notes, and snippets.

@mikesparr
Created March 5, 2018 23:01
Show Gist options
  • Save mikesparr/219641e1c22cbb57ba8d592850c12d36 to your computer and use it in GitHub Desktop.
Save mikesparr/219641e1c22cbb57ba8d592850c12d36 to your computer and use it in GitHub Desktop.
Docker batch delete local images and containers
#!/usr/bin/env bash
# optionally add --force flag
# stop all containers
echo "Stopping all containers"
docker ps -a | awk -F ' ' '{print $1}' | xargs docker stop
# remove all containers
echo "Removing all containers"
docker ps -a | awk -F ' ' '{print $1}' | xargs docker rm
# remove all images
echo "Removing all images"
docker images | awk -F ' ' '{print $3}' | xargs docker rmi
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment