Skip to content

Instantly share code, notes, and snippets.

@UrsaDK

UrsaDK/docker-clean.sh

Last active Nov 4, 2016
Embed
What would you like to do?
Reclame space used up by Docker on macOS
#!/usr/bin/env bash
echo "Removing unused containers ..."
docker ps --filter status=dead --filter status=exited -aq | xargs docker rm -v
echo
echo "Removing unused images ..."
docker images --no-trunc | grep '<none>' | awk '{ print $3 }' | xargs docker rmi
echo
echo "Removing unused volumes ..."
docker volume ls -qf dangling=true | xargs docker volume rm
: ${DOCKER_QCOW:="${HOME}/Library/Containers/com.docker.docker/Data/com.docker.driver.amd64-linux/Docker.qcow2"}
: ${DOCKER_QCOW_BACKUP:="${HOME}/Library/Containers/com.docker.docker/Data/com.docker.driver.amd64-linux/Docker.qcow2~"}
echo
echo "Rebuilding ${DOCKER_QCOW} ..."
$(du -hs ${DOCKER_QCOW} | awk '{ printf "%s -> ", $1 }' ) \
&& mv ${DOCKER_QCOW} ${DOCKER_QCOW_BACKUP} \
&& qemu-img convert -O qcow2 ${DOCKER_QCOW_BACKUP} ${DOCKER_QCOW} \
&& rm -f ${DOCKER_QCOW_BACKUP} \
&& $( du -hs ${DOCKER_QCOW} | awk '{ printf "%s", $1 }' )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment