docker/cli · info · cancelledErr

image prune has been cancelled

Error message

image prune has been cancelled

What it means

docker image prune asks for interactive confirmation unless --force/-f is given. In runPrune (cli/command/image/prune.go:80-87), prompt.Confirm shows a warning (dangling-only or all-images) and if the user answers no, the command returns cancelledErr wrapping this message. It signals a deliberate user abort, not a failure of the prune API; the cancelledErr type implements Cancelled() so callers can treat it as a non-fatal cancellation.

Source

Thrown at cli/command/image/prune.go:86

	danglingWarning = `WARNING! This will remove all dangling images.
Are you sure you want to continue?`
)

func runPrune(ctx context.Context, dockerCli command.Cli, options pruneOptions) (spaceReclaimed uint64, output string, err error) {
	pruneFilters := command.PruneFilters(dockerCli, options.filter.Value())
	pruneFilters.Add("dangling", strconv.FormatBool(!options.all))

	warning := danglingWarning
	if options.all {
		warning = allImageWarning
	}
	if !options.force {
		r, err := prompt.Confirm(ctx, dockerCli.In(), dockerCli.Out(), warning)
		if err != nil {
			return 0, "", err
		}
		if !r {
			return 0, "", cancelledErr{errors.New("image prune has been cancelled")}
		}
	}

	res, err := dockerCli.Client().ImagePrune(ctx, client.ImagePruneOptions{
		Filters: pruneFilters,
	})
	if err != nil {
		return 0, "", err
	}

	var sb strings.Builder
	if len(res.Report.ImagesDeleted) > 0 {
		sb.WriteString("Deleted Images:\n")
		for _, st := range res.Report.ImagesDeleted {
			if st.Untagged != "" {
				sb.WriteString("untagged: ")
				sb.WriteString(st.Untagged)
				sb.WriteByte('\n')

View on GitHub (pinned to e9452d6e78)

Solutions

  1. If you intended to prune, re-run and answer 'y' at the prompt
  2. In scripts/CI, pass --force (-f) to skip the confirmation: docker image prune -f
  3. Treat this error as an expected cancellation (it satisfies a Cancelled() interface), not a failure

Example fix

# before (CI hangs or cancels)
docker image prune -a
# after
docker image prune -a --force

When it happens

Trigger: Running `docker image prune` (optionally with -a) without --force and answering 'n' (or anything other than yes) at the 'Are you sure you want to continue? [y/N]' prompt, or the prompt being aborted (e.g. Ctrl-C/EOF handled as decline).

Common situations: Interactive use where the operator declines after reading the warning; automation/CI running prune without -f on a non-interactive stdin so the confirmation defaults to no; scripts that pipe empty input into docker image prune.

Related errors


AI-assisted analysis of docker/cli@e9452d6e78 (2026-08-01). Data as JSON: /data/errors/aa864e7a51539483.json. Report an issue: GitHub.