Home Explore Blog CI



docker

2nd chunk of `content/manuals/engine/manage-resources/pruning.md`
899031d797c6821ff0ca8385e10fda0bb4eaf9811752f6ef0000000100000807
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
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

Title: Pruning Volumes and Networks
Summary
Docker volumes, which are used by containers, are not automatically removed to prevent data loss. The `docker volume prune` command removes unused volumes. Similarly, the `docker network prune` command removes unused networks. Both commands prompt for confirmation by default, which can be bypassed with the `-f` or `--force` flag. The `--filter` flag can be used to narrow the scope of which volumes or networks are removed, for example removing all volumes without a specific label.