docker/cli · info · cancelledErr
container prune has been cancelled
Error message
container prune has been cancelled
What it means
Returned by runPrune wrapped in a cancelledErr (which implements Cancelled()) when the user answers 'no' to the interactive prune confirmation prompt. It is not a daemon failure; it signals the operation was intentionally aborted by the user. The prompt only appears when --force is not set.
Solutions
- Re-run and confirm with 'y', or use `docker container prune -f` to skip the prompt.
- In scripts, detect the Cancelled() error type and treat it as a no-op rather than a failure.
- Ensure stdin is a TTY if you want the prompt to appear interactively.
Example fix
// before docker container prune # user typed 'n' // after docker container prune -f
Defensive patterns
Strategy: try-catch
Validate before calling
// If non-interactive, default force=true to skip the prompt entirely.
if !interactive {
options.force = true
} Type guard
// Detect a user cancellation by the Cancelled() marker interface.
func isCancelled(err error) bool {
var c interface{ Cancelled() }
return errors.As(err, &c)
} Try / catch
_, _, err := runPrune(ctx, cli, options)
if err != nil {
var c interface{ Cancelled() }
if errors.As(err, &c) {
// user declined — not a failure
return nil
}
return err
} Prevention
- Pass --force in non-interactive scripts to avoid the prompt entirely.
- Always check for the Cancelled() interface to distinguish aborts from real errors.
- Ensure stdin is a TTY for interactive confirmation, or pre-pipe 'y'/'n' deliberately.
When it happens
Trigger: Running `docker container prune` (without -f) and typing 'n' at the 'Are you sure you want to continue?' prompt, or piping 'n'/'no' into stdin. prompt.Confirm returns false and the function returns the cancelled error.
Common situations: Interactive scripts that auto-answer 'n'. CI wrappers echoing 'n' to avoid accidental deletion. Aborted cleanup during manual exploration.
Related errors
- builder prune has been cancelled
- containers prune has been cancelled
- cannot attach to a stopped container, start it first
- cannot attach to a paused container, unpause it first
- cannot attach to a restarting container, wait until it is…
AI-assisted analysis of docker/cli@4f84911bfe (2026-08-07).
Data as JSON: /api/errors/ff4968474657e937.
Report an issue: GitHub.
Appendix: source
Thrown at cli/command/container/prune.go:74
flags.BoolVarP(&options.force, "force", "f", false, "Do not prompt for confirmation")
flags.Var(&options.filter, "filter", `Provide filter values (e.g. "until=<timestamp>")`)
return cmd
}
const warning = `WARNING! This will remove all stopped containers.
Are you sure you want to continue?`
func runPrune(ctx context.Context, dockerCli command.Cli, options pruneOptions) (spaceReclaimed uint64, output string, _ error) {
pruneFilters := command.PruneFilters(dockerCli, options.filter.Value())
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("container prune has been cancelled")}
}
}
res, err := dockerCli.Client().ContainerPrune(ctx, client.ContainerPruneOptions{
Filters: pruneFilters,
})
if err != nil {
return 0, "", err
}
var out strings.Builder
if len(res.Report.ContainersDeleted) > 0 {
out.WriteString("Deleted Containers:\n")
for _, id := range res.Report.ContainersDeleted {
out.WriteString(id + "\n")
}
spaceReclaimed = res.Report.SpaceReclaimed
}View on GitHub (pinned to 4f84911bfe)