github.com/docker/docker-ce@v17.12.1-ce-rc2+incompatible/components/cli/docs/reference/commandline/container_prune.md (about) 1 --- 2 title: "container prune" 3 description: "Remove all stopped containers" 4 keywords: container, prune, delete, remove 5 --- 6 7 <!-- This file is maintained within the docker/cli GitHub 8 repository at https://github.com/docker/cli/. Make all 9 pull requests against that repo. If you see this file in 10 another repository, consider it read-only there, as it will 11 periodically be overwritten by the definitive file. Pull 12 requests which include edits to this file in other repositories 13 will be rejected. 14 --> 15 16 # container prune 17 18 ```markdown 19 Usage: docker container prune [OPTIONS] 20 21 Remove all stopped containers 22 23 Options: 24 Options: 25 --filter filter Provide filter values (e.g. 'until=<timestamp>') 26 -f, --force Do not prompt for confirmation 27 --help Print usage 28 ``` 29 30 ## Description 31 32 Removes all stopped containers. 33 34 ## Examples 35 36 ### Prune containers 37 38 ```bash 39 $ docker container prune 40 WARNING! This will remove all stopped containers. 41 Are you sure you want to continue? [y/N] y 42 Deleted Containers: 43 4a7f7eebae0f63178aff7eb0aa39cd3f0627a203ab2df258c1a00b456cf20063 44 f98f9c2aa1eaf727e4ec9c0283bc7d4aa4762fbdba7f26191f26c97f64090360 45 46 Total reclaimed space: 212 B 47 ``` 48 49 ### Filtering 50 51 The filtering flag (`-f` or `--filter`) format is of "key=value". If there is more 52 than one filter, then pass multiple flags (e.g., `--filter "foo=bar" --filter "bif=baz"`) 53 54 The currently supported filters are: 55 56 * until (`<timestamp>`) - only remove containers created before given timestamp 57 * 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. 58 59 The `until` filter can be Unix timestamps, date formatted 60 timestamps, or Go duration strings (e.g. `10m`, `1h30m`) computed 61 relative to the daemon machine’s time. Supported formats for date 62 formatted time stamps include RFC3339Nano, RFC3339, `2006-01-02T15:04:05`, 63 `2006-01-02T15:04:05.999999999`, `2006-01-02Z07:00`, and `2006-01-02`. The local 64 timezone on the daemon will be used if you do not provide either a `Z` or a 65 `+-00:00` timezone offset at the end of the timestamp. When providing Unix 66 timestamps enter seconds[.nanoseconds], where seconds is the number of seconds 67 that have elapsed since January 1, 1970 (midnight UTC/GMT), not counting leap 68 seconds (aka Unix epoch or Unix time), and the optional .nanoseconds field is a 69 fraction of a second no more than nine digits long. 70 71 The `label` filter accepts two formats. One is the `label=...` (`label=<key>` or `label=<key>=<value>`), 72 which removes containers with the specified labels. The other 73 format is the `label!=...` (`label!=<key>` or `label!=<key>=<value>`), which removes 74 containers without the specified labels. 75 76 The following removes containers created more than 5 minutes ago: 77 78 ```bash 79 $ docker ps -a --format 'table {{.ID}}\t{{.Image}}\t{{.Command}}\t{{.CreatedAt}}\t{{.Status}}' 80 81 CONTAINER ID IMAGE COMMAND CREATED AT STATUS 82 61b9efa71024 busybox "sh" 2017-01-04 13:23:33 -0800 PST Exited (0) 41 seconds ago 83 53a9bc23a516 busybox "sh" 2017-01-04 13:11:59 -0800 PST Exited (0) 12 minutes ago 84 85 $ docker container prune --force --filter "until=5m" 86 87 Deleted Containers: 88 53a9bc23a5168b6caa2bfbefddf1b30f93c7ad57f3dec271fd32707497cb9369 89 90 Total reclaimed space: 25 B 91 92 $ docker ps -a --format 'table {{.ID}}\t{{.Image}}\t{{.Command}}\t{{.CreatedAt}}\t{{.Status}}' 93 94 CONTAINER ID IMAGE COMMAND CREATED AT STATUS 95 61b9efa71024 busybox "sh" 2017-01-04 13:23:33 -0800 PST Exited (0) 44 seconds ago 96 ``` 97 98 The following removes containers created before `2017-01-04T13:10:00`: 99 100 ```bash 101 $ docker ps -a --format 'table {{.ID}}\t{{.Image}}\t{{.Command}}\t{{.CreatedAt}}\t{{.Status}}' 102 103 CONTAINER ID IMAGE COMMAND CREATED AT STATUS 104 53a9bc23a516 busybox "sh" 2017-01-04 13:11:59 -0800 PST Exited (0) 7 minutes ago 105 4a75091a6d61 busybox "sh" 2017-01-04 13:09:53 -0800 PST Exited (0) 9 minutes ago 106 107 $ docker container prune --force --filter "until=2017-01-04T13:10:00" 108 109 Deleted Containers: 110 4a75091a6d618526fcd8b33ccd6e5928ca2a64415466f768a6180004b0c72c6c 111 112 Total reclaimed space: 27 B 113 114 $ docker ps -a --format 'table {{.ID}}\t{{.Image}}\t{{.Command}}\t{{.CreatedAt}}\t{{.Status}}' 115 116 CONTAINER ID IMAGE COMMAND CREATED AT STATUS 117 53a9bc23a516 busybox "sh" 2017-01-04 13:11:59 -0800 PST Exited (0) 9 minutes ago 118 ``` 119 120 ## Related commands 121 122 * [system df](system_df.md) 123 * [volume prune](volume_prune.md) 124 * [image prune](image_prune.md) 125 * [network prune](network_prune.md) 126 * [system prune](system_prune.md)