Skip to content

Instantly share code, notes, and snippets.

@zjhiphop
Last active September 8, 2016 05:46
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 zjhiphop/96cf364272e4b9c8104183703936e6e5 to your computer and use it in GitHub Desktop.
Save zjhiphop/96cf364272e4b9c8104183703936e6e5 to your computer and use it in GitHub Desktop.
docker-clean
#!/bin/bash
# remove exited containers:
docker ps --filter status=dead --filter status=exited -aq | xargs docker rm -v
# remove unused images:
docker images --no-trunc | grep '<none>' | awk '{ print $3 }' | xargs docker rmi
# remove unused volumes:
docker volume ls -qf dangling=true | xargs docker volume rm
# rebuild qcow file to release space
# if you don’t have qemo-img installed, please install it by ‘brew install qemu-img’ at first
cd /Users/jade/Library/Containers/com.docker.docker/Data/com.docker.driver.amd64-linux
mv Docker.qcow2 Docker.qcow2.original
du -hs Docker.qcow2.original
qemu-img convert -O qcow2 Docker.qcow2.original Docker.qcow2
rm Docker.qcow2.original
du -hs Docker.qcow2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment