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