Home Explore Blog CI



docker

3rd chunk of `content/manuals/engine/manage-resources/pruning.md`
e0df4b32ddfa5c8fda56e370f41245a37e9851d26444f7de0000000100000c12
Volumes can be used by one or more containers, and take up space on the Docker
host. Volumes are never removed automatically, because to do so could destroy
data.

```console
$ docker volume prune

WARNING! This will remove all volumes not used by at least one container.
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.

By default, all unused volumes are removed. You can limit the scope using
the `--filter` flag. For instance, the following command only removes
volumes which aren't labelled with the `keep` label:

```console
$ docker volume prune --filter "label!=keep"
```

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

## Prune networks

Docker networks don't take up much disk space, but they do create `iptables`
rules, bridge network devices, and routing table entries. To clean these things
up, you can use `docker network prune` to clean up networks which aren't used
by any containers.

```console
$ docker network prune

WARNING! This will remove all networks not used by at least one container.
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 unused networks are removed. You can limit the scope using
the `--filter` flag. For instance, the following command only removes
networks older than 24 hours:

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

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

## Prune everything

The `docker system prune` command is a shortcut that prunes images, containers,
and networks. Volumes aren't pruned by default, and you must specify the
`--volumes` flag for `docker system prune` to prune volumes.

```console
$ docker system prune

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

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

To also prune volumes, add the `--volumes` flag:

```console
$ docker system prune --volumes

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

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 unused containers, networks, and images are removed. You can
limit the scope using the `--filter` flag. For instance, the following command
removes items older than 24 hours:

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

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

Title: Pruning Docker Volumes, Networks, and Everything Else
Summary
The `docker volume prune` command removes unused volumes, which are not automatically removed to prevent data loss. The `docker network prune` command removes unused networks. The `docker system prune` command is a shortcut to prune images, containers, and networks. Volumes are not pruned by default with `docker system prune` but can be included with the `--volumes` flag. All prune commands prompt for confirmation by default, which can be bypassed with the `-f` or `--force` flag. The `--filter` flag can be used to limit the scope of what is removed.