docker/cli · error

cannot use --docker flag when --from is set

Error message

cannot use --docker flag when --from is set

What it means

When `docker context create` is given --from, it copies (store.Export/Import) an existing context wholesale, including its docker endpoint. Supplying --docker at the same time is contradictory — the copied endpoint and the explicit one would conflict — so createFromExistingContext rejects the combination when opts.endpoint is non-empty.

Source

Thrown at cli/command/context/create.go:134

	return contextStore.ResetTLSMaterial(name, &contextTLSData)
}

func checkContextNameForCreation(s store.Reader, name string) error {
	if err := store.ValidateContextName(name); err != nil {
		return err
	}
	if _, err := s.GetMetadata(name); !errdefs.IsNotFound(err) {
		if err != nil {
			return fmt.Errorf("error while getting existing contexts: %w", err)
		}
		return fmt.Errorf("context %q already exists", name)
	}
	return nil
}

func createFromExistingContext(s store.ReaderWriter, name string, fromContextName string, opts createOptions) error {
	if len(opts.endpoint) != 0 {
		return errors.New("cannot use --docker flag when --from is set")
	}
	reader := store.Export(fromContextName, &descriptionDecorator{
		Reader:      s,
		description: opts.description,
	})
	defer reader.Close()
	return store.Import(name, s, reader)
}

type descriptionDecorator struct {
	store.Reader
	description string
}

func (d *descriptionDecorator) GetMetadata(name string) (store.Metadata, error) {
	c, err := d.Reader.GetMetadata(name)
	if err != nil {
		return c, err

View on GitHub (pinned to e9452d6e78)

Solutions

  1. To clone with a different endpoint, drop --from and specify the endpoint fully: `docker context create newctx --docker "host=ssh://newhost"`.
  2. To clone as-is, drop --docker: `docker context create newctx --from oldctx`.
  3. To change an existing/cloned context's endpoint afterwards, use `docker context update newctx --docker "host=..."`.

Example fix

# before
docker context create staging --from prod --docker "host=ssh://staging-host"
# after
docker context create staging --from prod
docker context update staging --docker "host=ssh://staging-host"

When it happens

Trigger: `docker context create newctx --from oldctx --docker "host=tcp://..."` — any invocation where both --from and one or more --docker key=value pairs are set, hitting cli/command/context/create.go:133.

Common situations: Trying to 'clone a context but change its host' in one command; templated scripts that always append --docker while a user adds --from; misunderstanding --from as only copying description/metadata rather than the full endpoint set.

Related errors


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