Some handy commands for tidying up old Docker images and containers…
Remove Named Images
docker rmi `docker images --filter 'dangling=true' -q --no-trunc`
Remove Images With a Particular Name Pattern
Ish via here.
For example, removing repo2docker
default named containers which start r2d
:
docker images | awk '{ print $1,$2, $3 }' | grep r2d | awk '{print $3 }' | xargs -I {} docker rmi {}
For added aggression, use rmi -f {}
.
Remove Containers With a Particular Name Pattern
Via here.
docker ps -a | awk '{ print $1,$2 }' | grep r2d | awk '{print $1 }' | xargs -I {} docker rm {}
Remove Exited Containers
docker ps -a | grep Exit | cut -d ' ' -f 1 | xargs docker rm
PS lots of handy tips here: https://www.digitalocean.com/community/tutorials/how-to-remove-docker-images-containers-and-volumes
This can now be simplified using the new Docker prune commands – https://docs.docker.com/config/pruning/
@alex Thanks… handy…
If you want to delete all stopped containers, as well as free up all space completely (and void data from those stopped container volumes as well) use
docker system prune -a