pruner

package
v29.0.2+incompatible Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 17, 2025 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package pruner registers "prune" functions to be included as part of "docker system prune".

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func List

func List() iter.Seq2[ContentType, PruneFunc]

List iterates over all registered pruners, starting with known pruners in their predefined order, followed by any others (sorted alphabetically).

func Register

func Register(name ContentType, pruneFunc PruneFunc) error

Register registers a PruneFunc under the given name to be included in "docker system prune". It is designed to be called in an init function and is not safe for concurrent use.

For example:

 func init() {
	// Register the prune command to run as part of "docker system prune".
	if err := prune.Register(prune.TypeImage, prunerFn); err != nil {
		panic(err)
	}
}

Types

type ContentType

type ContentType string

ContentType is an identifier for content that can be pruned.

const (
	TypeContainer  ContentType = "container"
	TypeNetwork    ContentType = "network"
	TypeImage      ContentType = "image"
	TypeVolume     ContentType = "volume"
	TypeBuildCache ContentType = "buildcache"
)

Pre-defined content-types to prune. Additional types can be registered, and will be pruned after the list of pre-defined types.

type PruneFunc

type PruneFunc func(ctx context.Context, dockerCLI command.Cli, pruneOpts PruneOptions) (spaceReclaimed uint64, details string, _ error)

PruneFunc is the signature for prune-functions. The action performed depends on the [PruneOptions.Confirmed] field.

  • If [PruneOptions.Confirmed] is "false", the PruneFunc must be run in "dry-run" mode and return a short description of what content will be pruned (for example, "all stopped containers") instead of executing the prune. This summary is presented to the user as a confirmation message. It may return a ErrCancelled to indicate the operation was canceled or a ErrNotImplemented if the prune function is not implemented for the daemon's API version. Any other error is considered a validation error for the given options (such as a filter that is not supported).
  • If [PruneOptions.Confirmed] is "true", the PruneFunc must execute the prune with the given options.

After a successful prune the PruneFunc must return details about the content pruned;

  • spaceReclaimed is the amount of data removed (in bytes), if any.
  • details is arbitrary information about the content pruned to be presented to the user.

type PruneOptions

type PruneOptions struct {
	// Confirmed indicates whether pruning was confirmed (or "forced")
	// by the user. If not set, the PruneFunc must be run in "dry-run"
	// mode and return a short description of what content will be pruned
	// (for example, "all stopped containers") instead of executing the
	// prune. This summary is presented to the user as a confirmation message.
	Confirmed bool
	All       bool // Remove all unused content not just dangling (exact meaning differs per content-type).
	Filter    opts.FilterOpt
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL