-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdocker-clear-test-stuff.sh
41 lines (34 loc) · 1.26 KB
/
docker-clear-test-stuff.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
#!/bin/bash
# Cleans up the images and stopped containers after testing
IFS=$'\n'
# Stop any running test containers
echo "Stopping Test containers"
for line in $( docker ps -a | sed -n '1!p' ); do
containerID=$(echo ${line} | awk '{print $1}')
containerStatus=$(echo ${line} | awk '{print $1}')
imageName=$(echo ${line} | awk '{print $2}')
[[ ${imageName} =~ (ci_|\<none\>) ]] && \
echo "Stoping container: ${imageName} - ${containerID}" && \
docker stop ${containerID}
done
docker rm $(docker ps -a -q -f status=exited)
# Removing test containers
echo "Removing Test containers"
for line in $( docker ps -a | sed -n '1!p' ); do
containerID=$(echo ${line} | awk '{print $1}')
imageName=$(echo ${line} | awk '{print $2}')
[[ ${imageName} =~ (ci_|\<none\>) ]] && \
echo "Removing container: ${imageName} - ${containerID}" && \
docker rm ${containerID}
done
docker ps -a
# Remove Test images
echo "Removing Test images"
for line in $( docker images | sed -n '1!p' ); do
imageName=$(echo ${line} | awk '{print $1}')
imageID=$(echo ${line} | awk '{print $3}')
[[ ${imageName} =~ ^(ci_|\<none\>) ]] && \
echo "Removing image: ${imageName} - ${imageID}" && \
docker rmi ${imageID}
done
docker images