Docker Inc · Docker Inc

DescriptionRemove unused data
Usagedocker system prune [OPTIONS]

Remove all unused containers, networks, images (both dangling and unused), and optionally, volumes.

OptionDefaultDescription
-a, --allRemove all unused images not just dangling ones
--filterAPI 1.28+ Provide filter values (e.g. label=<key>=<value>)
-f, --forceDo not prompt for confirmation
--volumesPrune anonymous volumes

By default, volumes aren't removed to prevent important data from being deleted if there is currently no container using the volume. Use the --volumes flag when running the command to prune anonymous volumes as well:

Filtering (--filter)

The filtering flag (--filter) format is of "key=value". If there is more than one filter, then pass multiple flags (e.g., --filter "foo=bar" --filter "bif=baz").

When multiple filters are provided, they are combined as follows:

  • Multiple filters with different keys are combined using AND logic. An item must satisfy all filter conditions to be pruned.
  • Multiple filters with the same key are combined using OR logic. An item is pruned if it matches any of the values for that key.

For example, --filter "label=foo" --filter "until=24h" prunes items that have the foo label and were created more than 24 hours ago. Conversely, --filter "label=foo" --filter "label=bar" prunes items that have either the foo or bar label.

The currently supported filters are:

  • until (<timestamp>) - only remove containers, images, and networks created before given timestamp
  • label (label=<key>, label=<key>=<value>, label!=<key>, or label!=<key>=<value>) - only remove containers, images, networks, and volumes with (or without, in case label!=... is used) the specified labels.

The until filter can be Unix timestamps, date formatted timestamps, or Go duration strings supported by ParseDuration (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, 2006-01-02T15:04:05.999999999, 2006-01-02T07:00, and 2006-01-02. The local timezone on the daemon will be used if you do not provide either a Z or a +-00:00 timezone offset at the end of the timestamp. When providing Unix 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.

The label filter accepts two formats. One is the label=... (label=<key> or label=<key>=<value>), which removes containers, images, networks, and volumes with the specified labels. The other format is the label!=... (label!=<key> or label!=<key>=<value>), which removes containers, images, networks, and volumes without the specified labels.

Read the original on docs.docker.com ↗