Optimize Docker: Remove Unused Images and Containers
Delete images which consuming space on the Server is essential. For delete unused or inactive Docker resources like images, containers, and local volumes:
1. Remove Stopped Containers
To remove all stopped containers, run:
docker container prune
Prompt: You’ll be asked for confirmation. Add -f to skip the confirmation prompt:
docker container prune -f
2. Remove Unused Images
To remove all images that are not associated with any container:
docker image prune
- To remove all unused images, including dangling and untagged images:
docker image prune -a - Add
-fto skip confirmation:docker image prune -a -f
3. Remove Unused Volumes
To delete all unused volumes (those not associated with a container):
docker volume prune
- Add
-fto skip confirmation:docker volume prune -f
4. Remove Everything Inactive in One Go
If you want to clean up everything that is not active (containers, images, volumes, networks):
docker system prune
- To remove unused images, stopped containers, volumes, and networks:
docker system prune -a
Add -f to avoid confirmation:docker system prune -a -f