Knowledge

How to clean up Docker with prune (images, volumes, system)

#Development

Docker hangs on to stopped containers, unused images and dangling volumes, which quietly eat disk space. The prune commands clean them up, but a couple of flags decide how aggressive that cleanup is.

Published by Mark van Eijk on June 23, 2026 · 1 minute read

  1. See what Docker is using
  2. Prune everything unused at once
  3. Prune one resource type
  4. Skip the confirmation prompt

See what Docker is using

Before deleting anything, check where the space has gone:

docker system df

This breaks down disk usage by images, containers, local volumes and build cache.

Prune everything unused at once

docker system prune removes stopped containers, unused networks, dangling images and the build cache in one go:

docker system prune

It asks for confirmation and, by default, only removes dangling images (layers no longer referenced by any tag). To also remove every image not used by a running container, add -a:

docker system prune -a

Volumes are not touched unless you ask, because they usually hold data you care about. To include them:

docker system prune -a --volumes

Be careful with that last one: it deletes any volume not attached to a running container.

Prune one resource type

For finer control, prune a single category:

docker container prune   # remove all stopped containers
docker image prune       # remove dangling images
docker image prune -a    # remove all unused images
docker volume prune      # remove unused volumes
docker network prune     # remove unused networks
docker builder prune     # clear the build cache

Skip the confirmation prompt

In scripts or cron jobs, add -f to skip the "Are you sure?" prompt:

docker system prune -af

If you reached for prune because a server filled up, the disk pressure may be coming from more than Docker, see No space left on device on Ubuntu.

Subscribe to our newsletter

Do you want to receive regular updates with fresh and exclusive content to learn more about web development, hosting, security and performance? Subscribe now!

Related articles

Install PHP memcached extension on macOS

Docker hangs on to stopped containers, unused images and dangling volumes, which quietly eat disk space. The prune commands clean them up, but a couple of flags decide how aggressive that cleanup is.

Read more →

How to delete a local (and remote) Git branch

Docker hangs on to stopped containers, unused images and dangling volumes, which quietly eat disk space. The prune commands clean them up, but a couple of flags decide how aggressive that cleanup is.

Read more →