-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfinal_tasks.sh
More file actions
executable file
·44 lines (32 loc) · 1.05 KB
/
final_tasks.sh
File metadata and controls
executable file
·44 lines (32 loc) · 1.05 KB
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
#!/usr/bin/env bash
ONEDATA_STORAGE_PATH="/tmp/onedata"
# clear spaces data
echo "Clearing ${ONEDATA_STORAGE_PATH}"
docker run -v ${ONEDATA_STORAGE_PATH}:${ONEDATA_STORAGE_PATH} alpine sh -c "rm -rf ${ONEDATA_STORAGE_PATH}/*"
K8S_CONTAINER_NAME_LABEL_KEY="io.kubernetes.container.name"
CONTAINERS=$(docker ps -qa)
CONTAINERS_TO_REMOVE=${CONTAINERS}
for container in ${CONTAINERS}
do
if [ $(docker inspect --format "{{ index .Config.Labels \"io.kubernetes.container.name\"}}" ${container}) ]
then
CONTAINERS_TO_REMOVE=( "${CONTAINERS_TO_REMOVE[@]/$container}" )
fi
done
echo "Stalled docker containers to remove: "
echo ${CONTAINERS_TO_REMOVE}
echo "Removing stalled docker containers"
for container in ${CONTAINERS_TO_REMOVE}
do
docker kill ${container}
docker rm -fv ${container}
done
STALLED_DOCKER_VOLUMES=$(docker volume ls -q)
echo "Stalled docker volumes to remove: "
echo ${STALLED_DOCKER_VOLUMES}
echo "Removing stalled docker volumes"
for volume in ${STALLED_DOCKER_VOLUMES}
do
docker volume rm ${volume}
done
echo "Done"