Home Explore Blog CI



docker

1st chunk of `content/manuals/engine/manage-resources/pruning.md`
7a80a9115903453ff84c1c00f8e89d9446b3ca89e1cec92f0000000100000bf4
---
description: Free up disk space by removing unused resources with the prune command
keywords: pruning, prune, images, volumes, containers, networks, disk, administration,
  garbage collection
title: Prune unused Docker objects
aliases:
- /engine/admin/pruning/
- /config/pruning/
---

Docker takes a conservative approach to cleaning up unused objects (often
referred to as "garbage collection"), such as images, containers, volumes, and
networks. These objects are generally not removed unless you explicitly ask
Docker to do so. This can cause Docker to use extra disk space. For each type of
object, Docker provides a `prune` command. In addition, you can use `docker
system prune` to clean up multiple types of objects at once. This topic shows
how to use these `prune` commands.

## Prune images

The `docker image prune` command allows you to clean up unused images. By
default, `docker image prune` only cleans up _dangling_ images. A dangling image
is one that isn't tagged, and isn't referenced by any container. To remove
dangling images:

```console
$ docker image prune

WARNING! This will remove all dangling images.
Are you sure you want to continue? [y/N] y
```

To remove all images which aren't used by existing containers, use the `-a`
flag:

```console
$ docker image prune -a

WARNING! This will remove all images without at least one container associated to them.
Are you sure you want to continue? [y/N] y
```

By default, you are prompted to continue. To bypass the prompt, use the `-f` or
`--force` flag.

You can limit which images are pruned using filtering expressions with the
`--filter` flag. For example, to only consider images created more than 24
hours ago:

```console
$ docker image prune -a --filter "until=24h"
```

Other filtering expressions are available. See the
[`docker image prune` reference](/reference/cli/docker/image/prune.md)
for more examples.

## Prune containers

When you stop a container, it isn't automatically removed unless you started it
with the `--rm` flag. To see all containers on the Docker host, including
stopped containers, use `docker ps -a`. You may be surprised how many containers
exist, especially on a development system! A stopped container's writable layers
still take up disk space. To clean this up, you can use the `docker container
prune` command.

```console
$ docker container prune

WARNING! This will remove all stopped containers.
Are you sure you want to continue? [y/N] y
```

By default, you're prompted to continue. To bypass the prompt, use the `-f` or
`--force` flag.

By default, all stopped containers are removed. You can limit the scope using
the `--filter` flag. For instance, the following command only removes
stopped containers older than 24 hours:

```console
$ docker container prune --filter "until=24h"
```

Other filtering expressions are available. See the
[`docker container prune` reference](/reference/cli/docker/container/prune.md)
for more examples.

## Prune volumes

Volumes can be used by one or more containers, and take up space on the Docker

Title: Pruning Unused Docker Objects to Free Up Disk Space
Summary
Docker retains unused objects like images, containers, and volumes, potentially consuming significant disk space. The `docker image prune`, `docker container prune` commands can be used to remove dangling images or stopped containers. The `--filter` flag can be used to only remove objects that satisfy a certain condition (e.g. older than 24 hours). You will be prompted for confirmation by default, but this can be bypassed by the `-f` or `--force` flag.