-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathclean_docker.sh
executable file
·48 lines (41 loc) · 1.06 KB
/
clean_docker.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
#!/bin/bash
# AJN: [email protected]
echo ''
echo ''
# Stop running containers
echo 'Stopping all running containers...'
if [[ -n $(docker ps -q) ]]; then
docker stop $(docker ps -q)
else
echo "No running containers."
fi
# Removing stopped containers
echo ''
echo ''
echo 'Removing all stopped containers...'
if [[ -n $(docker ps -a -q) ]]; then
docker rm $(docker ps -a -q)
else
echo "No containers found."
fi
# Delete all images:
# Before doing so, make sure you are generating image from Dockerfile
# or have pushed your image to DockerHub
function del_images(){
if [[ -n $(docker images -q) ]]; then
docker rmi -f $(docker images -q)
else
echo "No images found."
fi
}
echo ''
echo ''
echo -e 'Erasing all images...\nMake sure you are generating image from a Dockerfile \nor have pushed your images to DockerHub.'
while true; do
read -p '*** Do you want to continue? ' resp
case $resp in
[Yy]* ) del_images; break;;
[Nn]* ) exit;;
* ) echo "Please answer yes [Yy]* or no [Nn]*";;
esac
done