-
Notifications
You must be signed in to change notification settings - Fork 10
/
docker-cleanup.sh
53 lines (50 loc) · 1.04 KB
/
docker-cleanup.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/bin/bash
#Description:Thiss script will help clean up docker containers and images.
#Author: Fleur Yeboah
#Date: March 9, 2022
#About this script: Docker containers and images can take up space on
your system. This script will help delete them and clear up space. It will :
#- Stop all running containers
#- Remove containers
#- Remove images
echo "Let's verify your identity before proceeding."
echo
sleep 2
echo "Please enter your username: "
echo
read U
id $U
if
[ $? -eq 0 ]
then
echo
echo "Warning!!! This script will remove ALL containers and images."
echo
echo "Do you wish to proceed?"
sleep 3
while true
do
echo "Enter yes / no "
read n
if
[ $n = "yes" ]
then
echo "Docker containers will now be stopped."
docker stop $(docker ps -aq)
sleep 2
echo
echo "Removing stopped containers..."
sleep 2
docker rm $(docker ps -aq)
echo
echo " Removing all images..."
sleep 2
docker rmi -f $(docker images -q)
break
elif [ $n = no ]
then
echo "No containers or images will be deleted."
exit
fi
done
fi