Skip to content

Instantly share code, notes, and snippets.

@appler1009
Created April 6, 2020 00:03
Show Gist options
  • Select an option

  • Save appler1009/15fdd28d21e856560528f3d27b290960 to your computer and use it in GitHub Desktop.

Select an option

Save appler1009/15fdd28d21e856560528f3d27b290960 to your computer and use it in GitHub Desktop.
#!/bin/bash
# Script that frees up docker-related diskspace, by removing old images and dangling resources.
echo Removing all but the latest app image...
docker images --format '{{.Repository}}:{{.Tag}}' | grep 'product-sigtran' | sort -r | tail -n +2 | xargs docker rmi
echo Removing exited containers...
docker ps --filter status=dead --filter status=exited -aq | xargs docker rm -v
echo Removing unused images...
docker images --no-trunc | grep '<none>' | awk '{ print $3 }' | xargs docker rmi
echo Remove unused volumes...
docker volume ls -qf dangling=true | xargs docker volume rm
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment