Skip to content

Instantly share code, notes, and snippets.

@elmijo
Created March 7, 2021 17:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save elmijo/cd637178a841be9b9a2f95eacdafb865 to your computer and use it in GitHub Desktop.
Save elmijo/cd637178a841be9b9a2f95eacdafb865 to your computer and use it in GitHub Desktop.
This script let you clean all in your docker environment
#!/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 ""
@elmijo
Copy link
Author

elmijo commented Mar 7, 2021

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

docker-clean

Remove all container, images and volumes

docker-clean -v

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment