docker commands
docker system prune
Free disk space by removing stopped containers, unused networks, dangling images and the build cache in one command.
docker system pruneAngle brackets are yours to fill in. Windows, Linux, macOS.
Examples for docker system prune
See how much space Docker uses
docker system dfShows the space used by images, containers, volumes and the build cache, and how much of each is reclaimable. Check this before you prune.
dockertoolsystemsubcommanddfdisk usageFree up disk space
docker system pruneRemoves stopped containers, networks no container uses, dangling images and build cache. Images with a tag and volumes are kept. It lists what it will remove and asks first.
dockertoolsystemsubcommandprunesubcommandRemove all unused images too
docker system prune -aAdds every image no container is using, tagged or not. This usually frees the most space, and the next build or run pulls images again.
Every image you are not currently running must be pulled or built again.
dockertoolsystemsubcommandprunesubcommand-aunused images tooClear the build cache
docker builder pruneRemoves only the cache BuildKit keeps between builds, which can grow to many gigabytes. Add -a to clear all of it, not only the unused part.
dockertoolbuildersubcommandprunesubcommandRemove only things older than a day
docker system prune --filter "until=24h"Keeps anything created in the last 24 hours, such as the containers and images from today's work.
dockertoolsystemsubcommandprunesubcommand--filter "until=24h"flag with value
Flags
- --all -a
- Also remove every image that no container uses, not only dangling ones.Every image you are not running must be pulled or built again.
- --volumes
- Also remove volumes that no container uses.Volumes hold data such as databases. Removed volumes cannot be recovered.
- --force -f
- Do not ask to confirm.
- --filter <key>=<value>
- Remove only what matches, such as until=24h for things older than a day.