This write-up has demonstrated how to prune unused Docker objects.
How to Prune Unused Docker Objects?
The “prune” is a powerful Docker command specifically used to remove unused Docker objects.
We have listed down methods to prune unused Docker objects:
- How to Prune Docker Images?
- How to Prune a Docker Container?
- How to Prune Docker Volume?
- How to Prune Docker Network?
- How to Prune the System?
How to Prune Docker Images?
To prune unused or dangling Docker images, go through the provided command:
In order to remove and clean all images that are not associated with at least one container, utilize the “-a” option along with the “docker image prune” command:
Use the “–filter” option to eliminate Docker images based on a condition or to remove the filtered images. The following command will remove all Docker images older than 24 hours:
How to Prune a Docker Container?
To remove the stopped, dangling, and unused Docker containers, utilize the “docker container prune” command:
In order to remove the filtered container, go through the provided command. The below command will filter and remove the container older the 24 hours:
To list down all Docker containers, utilize the “docker ps -a” command:
How to Prune Docker Volume?
Docker volume is used to preserve and store data generated by the container. The Docker volume is referred to as backup files or data that can be used for containers in the future.
To list down all Docker volumes, utilize the “docker volume ls” command:
To prune all Docker volume that is not associated with any container, go through the provided command:
How to Prune Docker Network?
Docker network allows you to connect a container to your preferred network. Users can connect to as many networks as they want.
To prune unused networks that are not used by any container, use the “docker network prune” command:
How to Prune Systems?
Pruning the system means removing all unused, dangling images, containers, networks, and volume. But volume cannot be directly removed by “docker system prune”. Therefore, users must pass the “–volumes” option along with the command to remove volumes.
In order to remove or prune the Docker system, check out the given command:
To remove volumes as well as all other Docker objects, utilize the “docker system prune” command along with the “–volumes” option:
We have taught you how to prune unused Docker objects.
Conclusion
To prune the unused Docker objects, use can separately prune components, such as Docker images with the help of the “docker images prune” command, Docker containers using the “docker container prune” command, and Docker volumes through the “docker volume prune” command. However, users can utilize the “docker system prune –volumes” command to remove all unused objects. This write-up has explained how to prune unused Docker objects.