Skip to content

Instantly share code, notes, and snippets.

@docertabum
Forked from rsignell-usgs/docker_clean.sh
Created May 21, 2021 11:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save docertabum/b33f96a08dd7a772a8815457ea96bbcd to your computer and use it in GitHub Desktop.
Save docertabum/b33f96a08dd7a772a8815457ea96bbcd to your computer and use it in GitHub Desktop.
Delete useless Docker image containers and volumes
#!/bin/bash
# from Kitware Jan 2017 newsletter
# remove dead and exited containers
docker ps --filter status=dead --filter status=exited -aq \
| xargs -r docker rm -v
# remove unused images
docker images --no-trunc | grep '<none>' \
| awk '{print $3 }' \
| xargs -r docker rmi
# remove unused volumes
docker volume ls -qf dangling=true \
| xargs -r docker volume rm
@docertabum
Copy link
Author

Additionally stop docker and:
Optimize-VHD -Path "C:\ProgramData\DockerDesktop\vm-data\DockerDesktop.vhdx" -Mode Full

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment