docker/cli · warning
network prune has been cancelled
Error message
network prune has been cancelled
What it means
Returned wrapped in a cancelledErr (which implements a Cancelled() marker method) from runPrune when the user answers 'no' to the interactive confirmation prompt and --force was not passed. This is not a real failure; it signals an intentional user cancellation of the destructive prune operation.
Solutions
- If you intend to prune, pass --force (-f) to skip the confirmation prompt.
- If cancellation was intentional, treat the non-zero exit as expected and ignore it in scripts.
- Check the Cancelled() marker on the error to distinguish cancellation from real failures.
Example fix
# before docker network prune # then type n # after docker network prune --force
Defensive patterns
Strategy: validation
Validate before calling
// In scripts, pass --force to avoid the prompt, or detect cancellation by marker
if !options.force {
// confirm interactively yourself, then run with --force if confirmed
} Try / catch
// Distinguish a user cancellation from a real error
err := runPrune(ctx, cli, opts)
if err != nil {
var c cancelledErr
if errors.As(err, &c) {
// user declined; not a failure
return nil
}
return err
} Prevention
- Use --force (-f) in automation to skip the confirmation entirely.
- Detect the Cancelled() marker interface to treat cancellation as a non-error.
- Do not pipe arbitrary input into the confirmation prompt.
When it happens
Trigger: Running 'docker network prune' without -f/--force and responding 'n' (or anything non-affirmative) at the 'Are you sure you want to continue?' prompt (lines 65-72).
Common situations: Scripted or interactive runs where the operator declines to delete unused networks; piping 'n' into the prompt; automation that forgot the --force flag.
Related errors
- every ip-range or gateway must have a corresponding subnet
- multiple overlapping subnet configuration is not supported
- plugin upgrade has been cancelled
- node ID not found in /info
- cannot supply extra formatting options to the pretty…
AI-assisted analysis of docker/cli@4f84911bfe (2026-08-07).
Data as JSON: /api/errors/ce690ffc93a4b385.
Report an issue: GitHub.
Appendix: source
Thrown at cli/command/network/prune.go:71
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 custom networks not used by at least one container.
Are you sure you want to continue?`
func runPrune(ctx context.Context, dockerCli command.Cli, options pruneOptions) (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 "", err
}
if !r {
return "", cancelledErr{errors.New("network prune has been cancelled")}
}
}
res, err := dockerCli.Client().NetworkPrune(ctx, client.NetworkPruneOptions{
Filters: pruneFilters,
})
if err != nil {
return "", err
}
var out strings.Builder
if len(res.Report.NetworksDeleted) > 0 {
out.WriteString("Deleted Networks:\n")
for _, id := range res.Report.NetworksDeleted {
out.WriteString(id + "\n")
}
}
View on GitHub (pinned to 4f84911bfe)