Last active
August 20, 2019 14:50
-
-
Save mabitt/c32f8d5de2f33c9721c8e3cc937ff3dd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
CREATED=$(docker ps -qa --no-trunc --filter "status=created") | |
if [ -n "$CREATED" ]; then | |
echo "Removing created conteiners - $HOSTNAME" | |
for ID in $CREATED ; do docker rm $ID ; done | |
fi | |
EXITED=$(docker ps -qa --no-trunc --filter "status=exited") | |
if [ -n "$EXITED" ]; then | |
echo "Removing exited conteiners - HOSTNAME" | |
for ID in $EXITED ; do docker rm $ID ; done | |
fi | |
echo "Removing images - $HOSTNAME" | |
for IMG in `docker images -q` ; do docker rmi $IMG ; done | |
#echo "Removing volumes - $HOSTNAME" | |
#for VOL in `docker volume ls -q` ; do docker volume rm $VOL ; done | |
if [[ $(docker node inspect self --format "{{ .ManagerStatus.Leader }}") = true ]]; then | |
echo "Leader node in Swarm - $HOSTNAME - Removing down nodes" | |
for NODE in `docker node ls | grep Down | awk '{print $1}'` ; do docker node rm $NODE ; done | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment