1#!/bin/bash
2
3echo "Running safe docker prune command"
4docker system prune --force
5
6if [[ "$1" != "--force" ]]; then
7 echo "Pass --force to clean up everything but beware this deletes all docker content on the"\
8 "system without further prompts (all images, containers and volumes are removed)"
9 exit 0
10fi
11
12echo "Now running highly unsafe full docker purge"
13
14if [[ "$(docker container ls --all --quiet | wc -l)" -gt 0 ]]; then
15 echo "Deleting all containers"
16 docker container rm --force $(docker container ls --all --quiet)
17else
18 echo "No containers found"
19fi
20
21if [[ "$(docker image ls --all --quiet | wc -l)" -gt 0 ]]; then
22 echo "Deleting all images"
23 docker image rm --force $(docker image ls --all --quiet)
24else
25 echo "No images found"
26fi
27
28if [[ "$(docker volume ls --quiet | wc -l)" -gt 0 ]]; then
29 echo "Deleting all volumes"
30 docker volume rm --force $(docker volume ls --quiet)
31else
32 echo "No volumes found"
33fi