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 prune
Save

Angle brackets are yours to fill in. Windows, Linux, macOS.

Examples for docker system prune

  • See how much space Docker uses

    docker system df
    Save

    Shows the space used by images, containers, volumes and the build cache, and how much of each is reclaimable. Check this before you prune.

    dockertoolsystemsubcommanddfdisk usage
  • Free up disk space

    docker system prune
    Save

    Removes 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.

    dockertoolsystemsubcommandprunesubcommand
  • Remove all unused images too

    docker system prune -a
    Save

    Adds 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 too
  • Clear the build cache

    docker builder prune
    Save

    Removes 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.

    dockertoolbuildersubcommandprunesubcommand
  • Remove only things older than a day

    docker system prune --filter "until=24h"
    Save

    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.