-
Clear images cache
You can use the command docker image prune
to remove all dangling and intermediate images:
First, let's list existing images:
By default intermediate images are hidden, you need to use the option -a (--all) to list all images:
Remove dangling images:
Check that dangling and intermediate images were deleted:
It's also possible to use this command to remove dangling images:
-
Clear stopped containers
You can use the command docker container prune
to remove all stopped containers:
Let's start a container:
Check the container (note that the container exited because it didn't run in foreground):
Remove stopped containers:
It's also possible to use this command to remove all containers with the status exited:
-
Clear unused networks
You can use the command docker network prune
to remove all unused networks (not attached to a running container):
Create a test network:
Remove unused networks:
-
Clear unused local volumes
You can use the command docker volume prune
to remove all unused local volumes (not attached to a running container):
Create a test volume:
Let's use the created volume:
Let's check the data in the volume:
Let's remove the unused volumes:
You could also remove specific volumes using the command docker volume rm
:
-
Clear all Docker unused objects (images, containers, networks, local volumes)
You can also use the command docker system prune
to remove all unused objects.
This will remove images cache, stopped containers, unused networks, and unused local volumes:
Remove unused objects: