Skip to content

Instantly share code, notes, and snippets.

@kytomaki
Created October 19, 2016 07:06
Show Gist options
  • Save kytomaki/d85f1c012cc5c6e3e0007ec91d4f26a5 to your computer and use it in GitHub Desktop.
Save kytomaki/d85f1c012cc5c6e3e0007ec91d4f26a5 to your computer and use it in GitHub Desktop.
Cleaning up after docker.
#!/bin/sh
#
# Create $HOME/.docker-gc/exclude which contains images you do not
# wish to remove.
#
# https://github.com/spotify/docker-gc#excluding-images-from-garbage-collection
docker run --rm \
-v /var/run/docker.sock:/var/run/docker.sock \
-v "$HOME"/.docker-gc:/etc/docker-gc \
-e FORCE_CONTAINER_REMOVAL=1 \
-e FORCE_IMAGE_REMOVAL=1 \
-e EXCLUDE_CONTAINERS_FROM_GC=/etc/docker-gc/exclude \
spotify/docker-gc
# Remove dangling volumes
DANGLING_VOLUMES=$(docker volume ls -qf dangling=true)
for VOLUME in $DANGLING_VOLUMES; do
docker volume rm "$VOLUME"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment