Created
October 27, 2015 18:32
-
-
Save ejholmes/f20f4d1efaeb60ec9b52 to your computer and use it in GitHub Desktop.
Docker maid
This file contains hidden or 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/sh | |
log() { | |
echo "=== [`date`] $*" >> /var/log/docker_maid.log | |
} | |
[ ! -S /var/run/docker.sock ] && (echo "Error: /var/run/docker.sock not available, bailing."; exit 1) | |
CONTAINERS=$(docker ps -q -a --filter "status=exited") | |
if [ ! -z "$CONTAINERS" ] | |
then | |
log "Cleaning unused docker containers." | |
docker rm $CONTAINERS | |
else | |
log "No unused containers found, not cleaning." | |
fi | |
IMAGES=$(docker images -f "dangling=true" -q) | |
if [ ! -z "$IMAGES" ] | |
then | |
log "Cleaning unused docker images." | |
docker rmi $IMAGES | |
else | |
log "No unused images found, not cleaning." | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment