Created
March 7, 2021 17:12
-
-
Save elmijo/cd637178a841be9b9a2f95eacdafb865 to your computer and use it in GitHub Desktop.
This script let you clean all in your docker environment
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
#!/bin/bash | |
CONTAINERS=$(docker ps -a -q) | |
IMAGES=$(docker images -a -q) | |
VOLUMES=$(docker volume ls -q) | |
echo "" | |
if [ -z "$CONTAINERS" ] | |
then | |
echo "No containers" | |
else | |
echo "Deleting all containers..." | |
docker rm -f $CONTAINERS | |
fi | |
if [ -z "$IMAGES" ] | |
then | |
echo "No images" | |
else | |
echo "Deleting all images..." | |
docker rmi $IMAGES | |
fi | |
if [ "$1" == "-v" ] | |
then | |
if [ -z "$VOLUMES" ] | |
then | |
echo "No volumes" | |
else | |
echo "Deleting all volumes..." | |
docker volume rm $(docker volume ls -q) | |
fi | |
fi | |
echo "" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Install
sudo curl -L "https://gist.githubusercontent.com/ElMijo/cd637178a841be9b9a2f95eacdafb865/raw/f5ae99bae1aefdfebc3cbb9b1f3d0189729f1b46/docker-clean.sh" -o /usr/local/bin/docker-clean
Usage
Remove all containers and images
Remove all container, images and volumes