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

  [ Rocketeers ](/)   

[Login](https://rocketeersapp.com) 

 On this page

 Knowledge
---------

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

### [\#Development](https://rocketee.rs/index.php/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](https://rocketee.rs/index.php/author/mark-van-eijk) on June 23, 2026 · 1 minute read

1. [See what Docker is using](#content-see-what-docker-is-using)
2. [Prune everything unused at once](#content-prune-everything-unused-at-once)
3. [Prune one resource type](#content-prune-one-resource-type)
4. [Skip the confirmation prompt](#content-skip-the-confirmation-prompt)

[\#](#content-see-what-docker-is-using "Permalink")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.

[\#](#content-prune-everything-unused-at-once "Permalink")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.

[\#](#content-prune-one-resource-type "Permalink")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

```

[\#](#content-skip-the-confirmation-prompt "Permalink")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](/no-space-left-on-device-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!

  Fill in your email address to receive updates  Subscribe 

#### More in [\#Development](https://rocketee.rs/index.php/development)

- [Install PHP memcached extension on macOS](https://rocketee.rs/index.php/install-php-memcached-extension-on-macos)
- [How to delete a local (and remote) Git branch](https://rocketee.rs/index.php/git-delete-local-branch)
- [Fix: Cannot connect to the Docker daemon at unix:///var/run/docker.sock](https://rocketee.rs/index.php/cannot-connect-to-docker-daemon)
- [git stash pop vs apply: save and restore changes](https://rocketee.rs/index.php/git-stash-pop)
- [What port does SSH use (and how to change it)](https://rocketee.rs/index.php/ssh-port)
- [How to checkout a Git tag](https://rocketee.rs/index.php/git-checkout-tag)

 [View all 12 articles →](https://rocketee.rs/index.php/development)
