JackCuthbert
4/25/2017 - 1:38 AM

Cleanup Docker

Useful snippets to clean up various aspects of your Docker installation.

#!/bin/bash

docker rmi $(docker images -a -q)
#!/bin/bash

docker volume ls -qf dangling=true
#!/bin/bash

# Delete all stopped containers
docker rm $( docker ps -q -f status=exited)

# Delete all dangling (unused) images
docker rmi $( docker images -q -f dangling=true)
#!/bin/bash

# Delete all stopped containers
docker ps -q -f status=exited | xargs --no-run-if-empty docker rm

# Delete all dangling (unused) images
docker images -q -f dangling=true | xargs --no-run-if-empty -- docker rmi

# xargs with --no-run-if-empty is even better as it does cleanly handle the case when there is nothing to be removed.