github.com/khulnasoft/cli@v0.0.0-20240402070845-01bcad7beefa/docs/reference/commandline/container_prune.md (about)

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