docker/cli · error
context "default" cannot be removed
Error message
context "default" cannot be removed
What it means
The 'default' context is synthesized at runtime from DOCKER_HOST, DOCKER_TLS settings, and CLI flags — it is not a file in the context store. `docker context rm` therefore special-cases the name 'default' in runRemove and refuses to delete it; removal continues for any other names given and the failures are joined into one error.
Source
Thrown at cli/command/context/remove.go:41
Short: "Remove one or more contexts",
Args: cli.RequiresMinArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
return runRemove(dockerCLI, opts, args)
},
ValidArgsFunction: completeContextNames(dockerCLI, -1, false),
DisableFlagsInUseLine: true,
}
cmd.Flags().BoolVarP(&opts.force, "force", "f", false, "Force the removal of a context in use")
return cmd
}
// runRemove removes one or more contexts.
func runRemove(dockerCLI command.Cli, opts removeOptions, names []string) error {
var errs []error
currentCtx := dockerCLI.CurrentContext()
for _, name := range names {
if name == "default" {
errs = append(errs, errors.New(`context "default" cannot be removed`))
} else if err := doRemove(dockerCLI, name, name == currentCtx, opts.force); err != nil {
errs = append(errs, err)
} else {
_, _ = fmt.Fprintln(dockerCLI.Out(), name)
}
}
return errors.Join(errs...)
}
func doRemove(dockerCli command.Cli, name string, isCurrent, force bool) error {
if isCurrent {
if !force {
return fmt.Errorf("context %q is in use, set -f flag to force remove", name)
}
// fallback to DOCKER_HOST
cfg := dockerCli.ConfigFile()
cfg.CurrentContext = ""
if err := cfg.Save(); err != nil {View on GitHub (pinned to e9452d6e78)
Solutions
- Exclude 'default' from bulk removals: `docker context ls -q | grep -v '^default$' | xargs -r docker context rm`.
- To change what the default points at, set DOCKER_HOST or use `docker context use <other>` instead of removing it.
- Remove only the named custom contexts you created; 'default' is virtual and costs nothing.
Example fix
# before docker context rm $(docker context ls -q) # after docker context ls -q | grep -v '^default$' | xargs -r docker context rm
When it happens
Trigger: `docker context rm default` or any `docker context rm` invocation whose argument list includes the literal name 'default' (cli/command/context/remove.go:40-41). --force does not bypass this check — force only applies to removing the context currently in use.
Common situations: Cleanup scripts doing `docker context rm $(docker context ls -q)` which sweeps in 'default'; users trying to 'reset' Docker Desktop's context setup; attempts to remove the default entry to stop it appearing in `docker context ls`.
Related errors
- default context cannot be created nor updated
- conflicting options: cannot specify both --host and --contex
- context metadata is not a valid DockerContext
- docker endpoint configuration is required
- cannot use --docker flag when --from is set
AI-assisted analysis of docker/cli@e9452d6e78 (2026-08-01).
Data as JSON: /data/errors/e30d870378ebda88.json.
Report an issue: GitHub.