docker/cli · error

no context specified

Error message

no context specified

What it means

`docker context inspect` with no arguments falls back to inspecting the current context (dockerCLI.CurrentContext()). If the resolved current context name is empty — no context argument, no currentContext in ~/.docker/config.json, and no DOCKER_CONTEXT — there is nothing to inspect and the command errors out rather than guessing.

Source

Thrown at cli/command/context/inspect.go:32

)

type inspectOptions struct {
	format string
	refs   []string
}

// newInspectCommand creates a new cobra.Command for `docker context inspect`
func newInspectCommand(dockerCLI command.Cli) *cobra.Command {
	var opts inspectOptions

	cmd := &cobra.Command{
		Use:   "inspect [OPTIONS] [CONTEXT] [CONTEXT...]",
		Short: "Display detailed information on one or more contexts",
		RunE: func(cmd *cobra.Command, args []string) error {
			opts.refs = args
			if len(opts.refs) == 0 {
				if dockerCLI.CurrentContext() == "" {
					return errors.New("no context specified")
				}
				opts.refs = []string{dockerCLI.CurrentContext()}
			}
			return runInspect(dockerCLI, opts)
		},
		ValidArgsFunction:     completeContextNames(dockerCLI, -1, false),
		DisableFlagsInUseLine: true,
	}

	flags := cmd.Flags()
	flags.StringVarP(&opts.format, "format", "f", "", flagsHelper.InspectFormatHelp)
	return cmd
}

func runInspect(dockerCli command.Cli, opts inspectOptions) error {
	getRefFunc := func(ref string) (any, []byte, error) {
		c, err := dockerCli.ContextStore().GetMetadata(ref)
		if err != nil {

View on GitHub (pinned to e9452d6e78)

Solutions

  1. Name the context explicitly: `docker context inspect default` (list names with `docker context ls`).
  2. Set a current context: `docker context use default` (or export DOCKER_CONTEXT=default).
  3. If embedding docker/cli, ensure the CLI options resolve a current context before invoking inspect.

Example fix

# before
docker context inspect
# after
docker context inspect default

When it happens

Trigger: `docker context inspect` with zero arguments while dockerCLI.CurrentContext() returns "" (cli/command/context/inspect.go:31). Normally CurrentContext defaults to "default", so this surfaces when the CLI is constructed/configured such that the current context resolves to an empty string (e.g. embedded CLI usage or unusual config states).

Common situations: Programs embedding docker/cli that build command.DockerCli without resolving a default context; stripped/managed environments with nonstandard config files; freshly scripted environments where DOCKER_CONTEXT is set to an empty string handling.

Related errors


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