forked from darribas/gds_env
-
Notifications
You must be signed in to change notification settings - Fork 1
/
cleanup.sh
48 lines (40 loc) · 1.33 KB
/
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
#! /bin/bash -e
printf "Running cleanup script...\n"
# Capture existing containers
CID=$(docker ps -aq)
# Check if we have any
if [ -z "$CID" ]
then
# If not, that's fine but we can say so
printf "No docker containers found...\n"
else
# we've found some
printf "Found docker containers... "
# Parse the container IDs into an array --
# although unlikely, it's possible that more
# than one container has been set up.
IFS=$'\n' CIDS=($CID)
# Let the user know what we found
#printf "%s, " "${CIDS[@]}"
printf "\n"
# For each container ID
for i in "${CIDS[@]}"
do
# Let the user know what we're up to
printf " Stopping and removing container id: ${i}\n"
# Capture the output
STOP=$(docker stop $i)
RM=$(docker rm $i)
if [ "$STOP" != "$i" ];
then
# Something has gone wrong
printf "Unexpected output from docker stop: $STOP\n"
fi
if [ "$RM" != "$i" ];
then
# Something has gone wrong
printf "Unexpected otuput from docker rm: $RM\n"
fi
done
fi
printf "Done.\n"