2022-02-11 12:26:16 +00:00
|
|
|
#!/bin/sh -x
|
2022-02-11 12:37:23 +00:00
|
|
|
# https://osmocom.org/projects/osmocom-servers/wiki/Docker_cache_clean_up
|
2018-04-06 07:31:39 +00:00
|
|
|
|
2022-02-11 12:37:23 +00:00
|
|
|
# simple image cleaning code in case docuum isn't running
|
2018-04-06 07:31:39 +00:00
|
|
|
# delete all but the latest images
|
2022-02-11 12:37:23 +00:00
|
|
|
if [ -z "$(docker ps -q -f name=docuum)" ]; then
|
|
|
|
IMAGES=`docker image ls | grep \^osmocom-build | grep -v latest | awk -F ' ' '{print $1":"$2}'`
|
|
|
|
for f in $IMAGES; do
|
|
|
|
docker image rm $f
|
|
|
|
done
|
|
|
|
fi
|
2018-04-06 07:31:39 +00:00
|
|
|
|
2022-02-11 12:09:38 +00:00
|
|
|
# delete all containers where we forgot to use --rm with docker run
|
|
|
|
CONTAINERS="$(docker ps -q -a -f status=exited -f status=created)"
|
|
|
|
if [ -n "$CONTAINERS" ]; then
|
|
|
|
docker rm $CONTAINERS
|
|
|
|
fi
|
|
|
|
|
2022-02-11 12:13:15 +00:00
|
|
|
# remove dangling images, containers, volumes, and networks (not tagged or associated with a container)
|
|
|
|
docker system prune -f
|