Deleting Docker Entities
1 min readJul 12, 2020
Purging all unused or dangling Images, Containers, Volumes, and Networks
- Introduction
- Docker File
- Basic Docker Commands
- Port and Volume Mapping
- Docker Networking
- Docker Storage
- Docker Compose
- Deleting Docker Entities (You are here!)
Docker provides a single command that will clean up any resources that are dangling (not associated with a container):
docker system prune
To additionally remove any stopped containers and all unused images (not just dangling images), add the -a
flag to the command:
docker system prune -a
Remove all the images
docker rmi $(docker images -a -q)
Remove all exited containers
docker rm $(docker ps -a -f status=exited -q)
Stop and remove all the containers
docker stop $(docker ps -a -q)
docker rm $(docker ps -a -q)
Reference:
[1] Melissa Anderson, How To Remove Docker Images, Containers, and Volumes (2017), digitalocean.com