During the testing or development process, we can create many Docker objects such as containers, images, networks or volumes that are no longer used. Unused Docker objects takes a disk space and can be removed. This tutorial demonstrates how to do that.
To remove unused Docker objects, the docker system
command with prune
argument can be used.
docker system prune
The command removes the following objects:
- Stopped containers.
- Dangling images - images without name and tag. The
docker images
command displays<none>
for image name and tag. - Networks that are not used by any container.
By default, volumes are not removed because data can be lost. To remove volumes that are not used by any container, the --volumes
option can be used.
docker system prune --volumes
By default, only dangling images are removed. To remove images that are not used by any container, the -a
or --all
option can be used.
docker system prune -a
By default, the command will prompt for the confirmation to remove objects. The -f
or --force
option can be used to ignore the confirmation.
docker system prune -f
All options can be combined in one command:
docker system prune -f -a --volumes
Leave a Comment
Cancel reply