docker/cli · error

no context specified

Error message

no context specified

What it means

`docker context inspect` with no positional arguments falls back to inspecting the current context. If CurrentContext() returns an empty string (no context selected via DOCKER_CONTEXT env var or config.json's currentContext), there is nothing to inspect, so it returns this error before querying the store.

Solutions

  1. Pass an explicit context name: `docker context inspect <name>`
  2. Create and select a context: `docker context create <name> ...` then `docker context use <name>`
  3. Set DOCKER_CONTEXT env var or set currentContext in ~/.docker/config.json

Example fix

// before
docker context inspect
// after
docker context inspect default
// or first
docker context use myctx && docker context inspect
Defensive patterns

Strategy: validation

Validate before calling

// Ensure a context is resolvable before inspecting with no args
if dockerCLI.CurrentContext() == "" {
    // either pass an explicit name or set a context first
    return runInspect(dockerCLI, inspectOptions{refs: []string{"default"}})
}

Prevention

When it happens

Trigger: Running `docker context inspect` with no args when DOCKER_CONTEXT is unset and config.json has no currentContext field.

Common situations: A fresh Docker installation with no context ever selected; config.json was hand-edited or wiped; a script assumes a default context exists.

Related errors


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

Appendix: 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 4f84911bfe)