How to remove unused object or data in Docker
Hello friend, in this article, I’d like to go over some of these additional methods and explain how they might be useful. we want to learn something trick to remove unused data in Docker .
Docker takes a conservative approach to cleaning up unused objects (often referred to as “garbage collection”), such as images, containers, volumes, and networks: these objects are generally not removed unless you explicitly ask Docker to do so. This can cause Docker to use extra disk space. For each type of object, Docker provides a
prune
command. In addition, you can usedocker system prune
to clean up multiple types of objects at once. This topic shows how to use theseprune
commands.
lets clean up docker from unused object, before we start be carefull everything is going to permanently deleted. and it with you own risk 😜
- Remove Unused docker image
to remove unused image we can execute simply command below
$ docker image prune
Usage : docker image prune [OPTIONS]
Options:
-a, — all Remove all unused images, not just dangling ones
— filter filter Provide filter values (e.g. ‘until=<timestamp>’)
-f, — force Do not prompt for confirmation
2. Remove unused data or volume in docker
you can simply execute this command to remove unused data or volume
$ docker volume prune
Usage: docker volume prune [OPTIONS]
Remove all unused local volumes
Options:
— filter filter Provide filter values (e.g. ‘label=<label>’)
-f, — force Do not prompt for confirmation
3. Remove unused container
syntax;
$ docker container prune
Usage: docker container prune [OPTIONS]
Options:
--filter filter Provide filter values (e.g. 'until=<timestamp>')
-f, --force Do not prompt for confirmation
4. remove unused network
syntax
$ docker network prune
Usage: docker network prune [OPTIONS]
Remove all unused networks
Options:
— filter filter Provide filter values (e.g. ‘until=<timestamp>’)
-f, — force Do not prompt for confirmation
5. Then how to Remove All
we can using this command
$ docker system prune
The ‘docker system prune’ is a Docker command that is used to remove or delete unused objects or data, it might be images, container, volume, or network as these objects are not removed unless we explicitly remove those objects, however, we need to specify the ‘–volumes’ option to remove volumes in Docker
Options:
Options:
-a, --all Remove all unused images not just dangling ones
--filter filter Provide filter values (e.g. 'label=<key>=<value>') -f, --force Do not prompt for confirmation
--volumes Prune volumes
That’s it…