How to Prune Unused Docker Objects
Docker is a well-known project development and deployment platform. It interacts with containers, images, volumes, and various other components. Sometimes, developers seek to free up storage space by deleting unnecessary Docker objects. These objects cannot be destroyed automatically unless Docker is instructed to do so. Docker provides the “” command that is used to remove and clean the Docker unused objects.
This write-up has demonstrated how to prune unused Docker objects.
Mục Lục
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?
To prune unused or dangling Docker images, go through the provided command:
>
docker image
prune
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:
>
docker image
prune
-a
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:
>
docker image
prune
-a
–filter
“until=24h”
How to Prune a Docker Container?
To remove the stopped, dangling, and unused Docker containers, utilize the “docker container prune” command:
>
docker container
prune
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:
docker container
prune
–filter
“until=24h”
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:
>
docker volume
ls
To prune all Docker volume that is not associated with any container, go through the provided command:
>
docker volume
prune
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:
>
docker network
prune
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:
>
docker system
prune
To remove volumes as well as all other Docker objects, utilize the “docker system prune” command along with the “–volumes” option:
>
docker system
prune
–volumes
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.