Created
March 5, 2018 23:01
-
-
Save mikesparr/219641e1c22cbb57ba8d592850c12d36 to your computer and use it in GitHub Desktop.
Docker batch delete local images and containers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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