Halloween DealsAmazon USHalloween week deals: useful picks before month-endAmazon US: current deals, useful picks and tech finds.Check DealsClean PCRecommendedOne scan can reveal what keeps slowing WindowsLook for cleanup and repair opportunities.Run ScanHalloween DealsAmazon USOctober picks are moving - compare before checkoutAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
VGSources
Blog

Docker Prune Explained: Safely Clean Up Images, Containers, Volumes, Networks and Build Cache

A practical guide to Docker prune commands: inspect usage, remove the right object type, protect recent or labelled resources, and avoid deleting persistent volumes by mistake.
Length8 min Posted Quest giverVGSources Team
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Docker prune is a family of cleanup commands, not one indiscriminate delete operation. Use the command that matches the object you have reviewed: prune stopped containers, dangling images, unused custom networks, volumes, or build cache independently. Start with docker system df, add an age or label filter when appropriate, and treat volume cleanup as a separate data-management decision.

What Docker prune removes

Docker stores several kinds of objects, and each has its own lifecycle. Images provide the filesystem layers used to create containers. Containers can remain after they stop. Networks connect containers, while volumes hold data outside a container’s writable layer. Build systems also retain cache layers to speed up future builds.

As an Amazon Associate I earn from qualifying purchases.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

The cleanup commands reflect those differences:

  • docker image prune targets images.
  • docker container prune targets stopped containers.
  • docker volume prune targets unused volumes.
  • docker network prune targets unused custom networks.
  • docker builder prune and docker buildx prune target build cache.
  • docker system prune combines several cleanup classes, but deliberately leaves volumes out unless you request them.

Docker’s documentation describes this policy as taking “a conservative approach to cleaning up unused objects (often referred to as ‘garbage collection’).” That conservatism matters most for volumes: an unused volume can still contain a database, save files, configuration, or other persistent data.

Inspect before you delete

Run:

docker system df

This gives you a host-specific view of Docker’s disk usage before any deletion. Use it to decide whether the problem is accumulated stopped containers, image layers, volumes, networks, or build cache. Do not interpret the totals as a universal benchmark: Docker’s examples can show values such as 1.84 kB or 13.5 MB because those numbers depend entirely on the host’s contents.

After the inspection, choose the narrowest command that addresses the space you actually need. A build cache problem does not require deleting images, and an old stopped container does not justify touching volumes.

Cleaning up images

Remove only dangling images

By default, the image prune command removes dangling images:

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
docker image prune

Dangling images are untagged layers that are no longer associated with a useful image tag. This is the lower-risk image cleanup because it does not broadly remove tagged images that might be useful for a later container start or rebuild.

Remove every image unused by a container

Add -a when you intentionally want to remove images that no container references, including tagged images:

docker image prune -a

A tag alone does not protect an image from this broader operation. Keep a private image that you expect to use again only if a container currently references it, or protect the cleanup with an appropriate review and filter. The trade-off is less disk usage now versus having to pull or rebuild an image later.

Keep recent images

An age filter can retain recent objects while targeting older ones:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
docker image prune -a --filter "until=24h"

The exact age window is your policy. A 24-hour value means objects newer than that window are excluded from the deletion set; it is not a promise about how much space will be recovered.

Removing stopped containers

Stopped containers are not automatically removed merely because their process exited. They remain until you remove them, unless they were created with the --rm option, which asks Docker to remove the container when it exits.

docker container prune

This command removes stopped containers. If you keep stopped containers for logs, debugging, or a quick restart, inspect them first and use a filter instead of deleting the entire stopped set.

docker container prune --filter "until=24h"

Removing a container is separate from removing its image. A container can be deleted while its image remains available, and image cleanup with -a can later remove that now-unreferenced image.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Pruning volumes without losing persistent data

Why volumes need a separate decision

Volumes can contain persistent application data even when no container is currently attached. For that reason, Docker never removes volumes automatically as part of ordinary cleanup. The default volume command limits itself to unused anonymous volumes:

docker volume prune

“Unused” means no container is using the volume at the time Docker evaluates the command; it does not mean the contents are unimportant. Treat every proposed volume deletion as a data review, not merely a cache cleanup.

Including named volumes

To include named volumes as well as anonymous ones, use:

docker volume prune -a

The -a behavior for volume pruning requires Docker API version 1.42 or newer. Named volumes often carry the deliberate, human-chosen storage for a service, so this is the highest-risk prune scope. Confirm that the data is disposable or backed up before proceeding.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Age-filtered volume cleanup

docker volume prune --filter "until=168h"

An age filter can reduce the chance of deleting a volume created recently during an active migration or test. It does not determine whether the data is valuable; it only narrows the age of candidates.

Removing unused networks

docker network prune removes unused custom networks:

docker network prune

Docker’s system networks—bridge, host, and none—are not pruned. The command therefore cleans up project-created networks that no longer have attached containers without removing those built-in networking choices.

Use an age filter if a network may be temporarily detached during a deployment:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
docker network prune --filter "until=24h"

Clearing build cache

Build cache is independent of ordinary image and container cleanup. Use the builder command when cached build layers are the source of disk usage:

docker builder prune

For builds managed through Buildx, use:

docker buildx prune

These commands target build cache rather than stopped containers, networks, or volumes. That separation lets you reclaim compilation layers without changing the runtime objects your services depend on.

What docker system prune does

The system command is a convenience operation that combines several default cleanup classes:

docker system prune

Without extra flags, it removes stopped containers, unused custom networks, dangling images, and unused build cache. It does not remove volumes by default.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use --volumes when you deliberately want the system operation to include unused anonymous volumes:

docker system prune --volumes

Use -a to broaden image cleanup from dangling images to all images not referenced by a container:

docker system prune -a

The broadest form combines both expansions:

docker system prune -a --volumes

This can remove stopped containers, unused custom networks, every image unused by a container, build cache, and unused anonymous volumes. Because it combines a wider image scope with volume deletion, reserve it for a reviewed maintenance window rather than routine housekeeping.

Filters: age windows and labels

The until filter

Prune commands support an until condition. For example:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
docker container prune --filter "until=24h"
docker image prune -a --filter "until=168h"

Choose a window that matches your rollback needs. A short window is suitable for disposable build debris; a longer window gives an operations team more time to inspect a stopped container or recover a recently created artifact.

Label conditions

Where the specific prune command supports label filtering, labels can target objects or protect them. For example:

docker container prune --filter "label!=keep"

This expresses a policy of excluding objects marked with the keep label from the deletion set. Check the command’s help output and your Docker version before relying on a label expression in automation, because filter support is command-specific.

How multiple filters combine

Different filter keys are ANDed: an object must satisfy every different condition. Repeating the same key creates OR behavior among those values. In practical terms, an object selected by both an age rule and a label rule must pass the age condition and the label condition, while repeated label values broaden the acceptable label matches.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Quote filter expressions in shell scripts so the comparison operator and value reach Docker unchanged:

docker image prune -a 
  --filter "until=168h" 
  --filter "label!=keep"
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Command comparison

Goal Command Default deletion scope Important caution or expansion
Remove dangling images docker image prune Dangling images Use -a to include all images unused by containers.
Remove all images unused by containers docker image prune -a Dangling and other unreferenced images Tagged images you want later can also be removed.
Remove stopped containers docker container prune All stopped containers unless filtered Containers started with --rm are removed automatically on exit.
Remove anonymous unused volumes docker volume prune Unused anonymous volumes Volumes can hold persistent data.
Remove named and anonymous unused volumes docker volume prune -a Unused named and anonymous volumes Requires API 1.42 or newer and carries the greatest data risk.
Remove unused custom networks docker network prune Unused custom networks bridge, host, and none are retained.
Remove build cache docker builder prune Builder cache Use docker buildx prune for Buildx-managed cache.
Combined cleanup docker system prune Stopped containers, unused custom networks, dangling images, and build cache Volumes are excluded unless --volumes is supplied.
Broad combined cleanup docker system prune -a --volumes Combined cleanup plus all unused images and unused anonymous volumes Review every category before running.

A safe, repeatable prune workflow

  1. Measure first. Run docker system df and identify which object type is consuming space.
  2. List the deletion boundary. Decide whether you need stopped-container cleanup, dangling-image cleanup, cache cleanup, network cleanup, or volume cleanup. Do not start with the broadest command simply because it is shorter.
  3. Choose a narrow command. Run the matching object-specific prune command. This makes the confirmation prompt and resulting deletions easier to reason about.
  4. Protect recent work. Add an until filter such as --filter "until=24h" when recent objects must remain available.
  5. Apply labels deliberately. Use a supported label condition such as label!=keep when your object-labeling policy is established and tested.
  6. Review volumes separately. Keep the default system prune volume-free unless you have explicitly checked anonymous volume contents. Use volume -a only when named-volume deletion is intentional and the API requirement is met.
  7. Confirm the result. Run docker system df again and verify that the expected category changed without relying on a generic reclaimed-space estimate.
  8. Automate only after testing. Add --force only when you intentionally want to skip the confirmation prompt. A forced command should still use the same narrow scope and filters as an interactive one.

Common mistakes and how to avoid them

Assuming “prune” means volumes are included

They are not included in ordinary docker system prune. If persistent data is the concern, this default is a safety feature, not a missing option.

Using -a without understanding image references

Image -a removes images not referenced by any container, including tagged images. Use it when you can recreate or pull those images, not as a routine replacement for dangling-image cleanup.

Deleting every stopped container during debugging

Stopped containers can preserve a useful failed state for inspection. Apply an age filter or remove only after collecting the logs and details you need.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Treating an unused volume as disposable

Docker’s definition of unused is about attachment, not business value. A detached volume may be the only copy of an application’s persistent files, so volume pruning belongs in a backup and retention policy.

Expecting one command to reclaim a fixed amount

Reclaimed space varies with the host’s images, layers, containers, and cache. The 1.84 kB and 13.5 MB totals shown in Docker examples illustrate command output for particular hosts; they are not general performance or storage guarantees.

Choosing the right command

  • If only untagged image debris has accumulated, use docker image prune.
  • If old stopped runs are the problem, use docker container prune, preferably with an age filter.
  • If builds are consuming the disk, use docker builder prune or docker buildx prune.
  • If abandoned project networks are cluttering the host, use docker network prune.
  • If anonymous volumes are known to be disposable, use docker volume prune after reviewing the data risk.
  • Use docker system prune for a coordinated cleanup of the default non-volume categories, and reserve docker system prune -a --volumes for a deliberate, fully reviewed reset of unused objects.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More quests from Patch Notes

  1. How to Set Up a RedM (RDR2) Server in 2026: License Key, txAdmin and server.cfg, Step by StepBlog11min
  2. Best RedM (RDR2) Server Hosting in 2026: Comparing Four Hosts on Slots, Memory and PriceBlog10min
  3. How to Host a Mindustry Server in 2026: server-release.jar, Port 6567 and the Commands That MatterBlog7min
Recommended PC Tool
Recommended PC Tool
Crashes, No Sound, or Screen Glitches?Free driver scan
Windows Errors? Fix Them Before They SpreadFree repair scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.