docker/cli · warning · notFoundErr

context does not exist

Error message

context %q does not exist

What it means

Returned by checkContextExists (remove.go:78) as a notFoundErr when os.Stat on the context's MetadataPath reports os.IsNotExist. This pre-check runs before the actual Remove call so that a missing context produces a clear 'does not exist' message rather than a generic store error. The wrapped error implements the NotFound() marker interface.

Solutions

  1. List existing contexts to confirm the name: 'docker context ls'.
  2. Check spelling and tab-complete against 'docker context ls --format '{{.Name}}''.
  3. If the contexts directory was wiped, recreate needed contexts with 'docker context create'.
  4. Pass -f only if you intentionally want to bypass the existence check (e.g., cleaning stale references).

Example fix

# before
docker context rm produciton
# after
docker context ls
docker context rm production
Defensive patterns

Strategy: validation

Validate before calling

// Confirm a context exists before attempting removal.
func contextExists(cli command.Cli, name string) bool {
	for _, m := range cli.ContextStore().GetStorageInfo(name).MetadataPath {
		_ = m // placeholder
	}
	_, err := os.Stat(cli.ContextStore().GetStorageInfo(name).MetadataPath)
	return !os.IsNotExist(err)
}

Type guard

func isNotFound(err error) bool {
	var nfe interface{ NotFound() bool }
	return errors.As(err, &nfe) && nfe.NotFound()
}

Try / catch

if err := cli.ContextRemove(name); err != nil {
	var nfe interface{ NotFound() bool }
	if errors.As(err, &nfe) && nfe.NotFound() {
		// already gone; treat as success in idempotent scripts
	}
}

Prevention

When it happens

Trigger: Running 'docker context rm <name>' (without -f) where <name> is not 'default' but no metadata file exists on disk for it. This includes typos, contexts removed out-of-band, or names that were never created. With -f the pre-check is skipped and the underlying store.Remove determines the outcome.

Common situations: Typo in the context name; context already deleted; context name taken from stale documentation; home/config directory reset so the contexts directory is empty.

Related errors


AI-assisted analysis of docker/cli@4f84911bfe (2026-08-07). Data as JSON: /api/errors/635491a3e1c20f05. Report an issue: GitHub.

Appendix: source

Thrown at cli/command/context/remove.go:78

			return err
		}
	}

	if !force {
		// TODO(thaJeztah): instead of checking before removing, can we make ContextStore().Remove() return a proper errdef and ignore "not found" errors?
		if err := checkContextExists(dockerCli, name); err != nil {
			return err
		}
	}
	return dockerCli.ContextStore().Remove(name)
}

// checkContextExists returns an error if the context directory does not exist.
func checkContextExists(dockerCli command.Cli, name string) error {
	contextDir := dockerCli.ContextStore().GetStorageInfo(name).MetadataPath
	_, err := os.Stat(contextDir)
	if os.IsNotExist(err) {
		return notFoundErr{fmt.Errorf("context %q does not exist", name)}
	}
	// Ignore other errors; if relevant, they will produce an error when
	// performing the actual delete.
	return nil
}

type notFoundErr struct{ error }

func (notFoundErr) NotFound() {}

View on GitHub (pinned to 4f84911bfe)