2016-08-31 12:57:32 -04:00
# container prune
2023-01-06 13:04:05 -05:00
<!-- - MARKER_GEN_START -->
2016-08-31 12:57:32 -04:00
Remove all stopped containers
2023-01-06 13:04:05 -05:00
### Options
| Name | Type | Default | Description |
|:----------------------|:---------|:--------|:-------------------------------------------------|
| [`--filter` ](#filter ) | `filter` | | Provide filter values (e.g. `until=<timestamp>` ) |
| `-f` , `--force` | | | Do not prompt for confirmation |
<!-- - MARKER_GEN_END -->
2016-08-31 12:57:32 -04:00
2017-02-07 18:42:48 -05:00
## Description
Removes all stopped containers.
2016-10-10 11:07:32 -04:00
## Examples
2016-08-31 12:57:32 -04:00
2017-02-07 18:42:48 -05:00
### Prune containers
2021-08-21 08:54:14 -04:00
```console
2016-08-31 12:57:32 -04:00
$ docker container prune
WARNING! This will remove all stopped containers.
Are you sure you want to continue? [y/N] y
Deleted Containers:
4a7f7eebae0f63178aff7eb0aa39cd3f0627a203ab2df258c1a00b456cf20063
f98f9c2aa1eaf727e4ec9c0283bc7d4aa4762fbdba7f26191f26c97f64090360
Total reclaimed space: 212 B
```
2023-01-06 13:28:29 -05:00
### <a name="filter"></a> Filtering (--filter)
2016-12-07 17:02:13 -05:00
2018-01-02 13:40:23 -05:00
The filtering flag (`--filter`) format is of "key=value". If there is more
2016-12-07 17:02:13 -05:00
than one filter, then pass multiple flags (e.g., `--filter "foo=bar" --filter "bif=baz"` )
The currently supported filters are:
* until (`< timestamp > `) - only remove containers created before given timestamp
2017-04-10 14:08:40 -04:00
* label (`label=< key > `, `label=<key>=<value>` , `label!=<key>` , or `label!=<key>=<value>` ) - only remove containers with (or without, in case `label!=...` is used) the specified labels.
2016-12-07 17:02:13 -05:00
The `until` filter can be Unix timestamps, date formatted
timestamps, or Go duration strings (e.g. `10m` , `1h30m` ) computed
relative to the daemon machine’ s time. Supported formats for date
formatted time stamps include RFC3339Nano, RFC3339, `2006-01-02T15:04:05` ,
2023-01-30 22:18:12 -05:00
`2006-01-02T15:04:05.999999999` , `2006-01-02T07:00` , and `2006-01-02` . The local
2016-12-07 17:02:13 -05:00
timezone on the daemon will be used if you do not provide either a `Z` or a
2023-12-13 09:16:56 -05:00
`+-00:00` timezone offset at the end of the timestamp. When providing Unix
2016-12-07 17:02:13 -05:00
timestamps enter seconds[.nanoseconds], where seconds is the number of seconds
that have elapsed since January 1, 1970 (midnight UTC/GMT), not counting leap
seconds (aka Unix epoch or Unix time), and the optional .nanoseconds field is a
fraction of a second no more than nine digits long.
2017-04-10 14:08:40 -04:00
The `label` filter accepts two formats. One is the `label=...` (`label=< key > ` or `label=<key>=<value>` ),
which removes containers with the specified labels. The other
format is the `label!=...` (`label!=< key > ` or `label!=<key>=<value>` ), which removes
containers without the specified labels.
2016-12-07 17:02:13 -05:00
The following removes containers created more than 5 minutes ago:
2017-02-07 18:42:48 -05:00
2021-08-21 08:54:14 -04:00
```console
2016-12-07 17:02:13 -05:00
$ docker ps -a --format 'table {{.ID}}\t{{.Image}}\t{{.Command}}\t{{.CreatedAt}}\t{{.Status}}'
2017-02-07 18:42:48 -05:00
2016-12-07 17:02:13 -05:00
CONTAINER ID IMAGE COMMAND CREATED AT STATUS
61b9efa71024 busybox "sh" 2017-01-04 13:23:33 -0800 PST Exited (0) 41 seconds ago
53a9bc23a516 busybox "sh" 2017-01-04 13:11:59 -0800 PST Exited (0) 12 minutes ago
$ docker container prune --force --filter "until=5m"
2017-02-07 18:42:48 -05:00
2016-12-07 17:02:13 -05:00
Deleted Containers:
53a9bc23a5168b6caa2bfbefddf1b30f93c7ad57f3dec271fd32707497cb9369
Total reclaimed space: 25 B
$ docker ps -a --format 'table {{.ID}}\t{{.Image}}\t{{.Command}}\t{{.CreatedAt}}\t{{.Status}}'
2017-02-07 18:42:48 -05:00
2016-12-07 17:02:13 -05:00
CONTAINER ID IMAGE COMMAND CREATED AT STATUS
61b9efa71024 busybox "sh" 2017-01-04 13:23:33 -0800 PST Exited (0) 44 seconds ago
```
The following removes containers created before `2017-01-04T13:10:00` :
2017-02-07 18:42:48 -05:00
2021-08-21 08:54:14 -04:00
```console
2016-12-07 17:02:13 -05:00
$ docker ps -a --format 'table {{.ID}}\t{{.Image}}\t{{.Command}}\t{{.CreatedAt}}\t{{.Status}}'
2017-02-07 18:42:48 -05:00
2016-12-07 17:02:13 -05:00
CONTAINER ID IMAGE COMMAND CREATED AT STATUS
53a9bc23a516 busybox "sh" 2017-01-04 13:11:59 -0800 PST Exited (0) 7 minutes ago
4a75091a6d61 busybox "sh" 2017-01-04 13:09:53 -0800 PST Exited (0) 9 minutes ago
$ docker container prune --force --filter "until=2017-01-04T13:10:00"
2017-02-07 18:42:48 -05:00
2016-12-07 17:02:13 -05:00
Deleted Containers:
4a75091a6d618526fcd8b33ccd6e5928ca2a64415466f768a6180004b0c72c6c
Total reclaimed space: 27 B
$ docker ps -a --format 'table {{.ID}}\t{{.Image}}\t{{.Command}}\t{{.CreatedAt}}\t{{.Status}}'
2017-02-07 18:42:48 -05:00
2016-12-07 17:02:13 -05:00
CONTAINER ID IMAGE COMMAND CREATED AT STATUS
53a9bc23a516 busybox "sh" 2017-01-04 13:11:59 -0800 PST Exited (0) 9 minutes ago
```
2017-02-07 18:42:48 -05:00
## Related commands
2016-08-31 12:57:32 -04:00
* [system df ](system_df.md )
2016-10-10 11:07:32 -04:00
* [volume prune ](volume_prune.md )
* [image prune ](image_prune.md )
2016-10-18 00:36:52 -04:00
* [network prune ](network_prune.md )
2016-08-31 12:57:32 -04:00
* [system prune ](system_prune.md )