✦ For everyone, free.

Practical knowledge for real and everyday life

Home

19.3.2 System Prune Command

A focused guide to System Prune Command, connecting core concepts with practical Docker and container operations.

docker system prune removes all unused Docker resources from the host in a single command. It is the broadest cleanup command available in the Docker CLI, targeting stopped containers, unused networks, dangling images, and all build cache simultaneously. It is designed for situations where you want to reclaim as much disk space as possible without manually targeting each resource type individually.

Basic Usage

docker system prune

Docker displays a warning explaining what will be removed and prompts for confirmation:

WARNING! This will remove:
  - all stopped containers
  - all networks not used by at least one container
  - all dangling images
  - all dangling build cache

Are you sure you want to continue? [y/N]

After confirmation, Docker processes each resource type and prints the deleted items along with a summary of total reclaimed space:

Deleted Containers:
a1b2c3d4e5f6
b2c3d4e5f6a1

Deleted Networks:
my_old_network

Deleted Images:
deleted: sha256:012def345abc...

Total reclaimed space: 1.4GB

What Gets Removed by Default

Stopped Containers

All containers not currently running are removed. This includes containers with status Exited, Created, and Dead. Running and paused containers are not affected.

Unused Networks

All networks not currently connected to at least one running container are removed. The three default Docker networks (bridge, host, none) are never removed even if unused, as they are required by Docker itself.

Dangling Images

Dangling images are images that are not tagged and not referenced by any container. They appear as <none>:<none> in docker images output and are typically left behind when a newer image is built with the same name, displacing the old one. By default, docker system prune only removes dangling images, not all unused images.

Build Cache

All build cache entries not currently locked by an active build are removed. This includes intermediate layer caches from previous docker build and docker buildx build invocations.

Flags

--force / -f

Skips the confirmation prompt. Required for non-interactive use in scripts and automated pipelines:

docker system prune --force
--volumes

Extends the cleanup to also include unused volumes. Without this flag, Docker volumes are never touched by docker system prune, even if they are not referenced by any container:

docker system prune --volumes

With --volumes, both named volumes and anonymous volumes that are not currently mounted by any running or stopped container are removed. This is permanent and irreversible — only use it when you are certain no volume data needs to be preserved.

--all / -a

Extends image removal beyond dangling images to include all images not currently used by at least one running container. This removes tagged images that are stored locally but not actively running:

docker system prune --all

Use --all with care in development environments where you want to keep base images locally to avoid re-downloading them on the next build. On disposable CI runners, --all is appropriate because images are pulled fresh for each job anyway.

--filter

Restricts pruning to resources that match specific criteria. The most commonly used filter is until, which limits removal to resources created or unused before a given point in time:

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

This removes only resources that have been unused for more than 24 hours. Other filter keys depend on the resource type:

docker system prune --filter "label=environment=staging"

This removes only resources with the specified label.

Combining Flags

Flags can be combined to achieve more thorough cleanup:

docker system prune --all --volumes --force

This removes all stopped containers, all unused networks, all unused images (not just dangling), all unused volumes, and all build cache, without prompting for confirmation. This is the maximum cleanup option.

What docker system prune Does Not Remove

  • Running or paused containers and their writable layers.
  • Named and anonymous volumes currently mounted by running containers (unless --volumes is used, in which case only unmounted volumes are removed).
  • Images currently used by running containers (even with --all).
  • The default bridge, host, and none networks.
  • Images pinned by containers that are stopped (without --all, only dangling images are removed; with --all, stopped container images are removed too).

Relationship to Individual Prune Commands

docker system prune is a convenience wrapper that runs the equivalent of:

docker container prune
docker network prune
docker image prune          # (or docker image prune --all with --all flag)
docker builder prune
docker volume prune         # (only when --volumes is passed)

When you need more granular control — for example, pruning only containers but keeping images and volumes — use the individual prune commands instead.

Practical Usage Scenarios

Routine cleanup on a development machine:

docker system prune --force

Removes stopped containers, dangling images, unused networks, and build cache without touching named volumes or current images.

Aggressive cleanup to maximize disk space:

docker system prune --all --volumes --force

Removes everything unused. Best on disposable hosts or before a fresh start.

Cleanup limited to resources older than 48 hours:

docker system prune --filter "until=48h" --force

Preserves recently stopped containers and recently built images while removing older unused resources.

CI/CD post-job cleanup:

docker system prune --all --force

Leaves the host in a clean state for the next job without consuming disk on accumulated images and containers.

Content in this section