How to cleanup Docker
Docker doesn’t remove unused objects such as containers, images, volumes, and networks unless you explicitly tell it to do so. How To Remove them?
Removing All Unused Objects
Remove stopped containers, all dangling images, and all unused networks:
You can also include all unused volumes, then add --volumes
:
Docker Containers
Remove selected container
Remove all stopped containers
To remove all stopped containers use:
You can also list what will be removed:
Stop and remove all containers
Docker Images
You can list them:
Remove selected image
Remove dangling images
A dangling image is an image that is not tagged and is not used by any container. You can remove them by:
Remove all unused images
To remove all images which are not referenced by any existing container,
not just the dangling ones, use the prune
command with the -a
flag:
Docker Networks
You can list them with:
Remove selected network
Remove all unused networks
Use the docker network prune
command to remove all unused networks.
Remove all networks that are created more than 12 hours ago: