docker/cli · error

no remote command specified

Error message

no remote command specified

What it means

Returned by Spec.Command when remoteCommandAndArgs is empty. Unlike Spec.Args (which builds the connection args only), Command is meant to produce a full ssh invocation that runs a remote command, so it requires at least one command token. Without a command there is nothing to execute on the remote host.

Solutions

  1. Pass the remote command as the variadic args, e.g. spec.Command([]string{"-o", "..."}, "docker", "context", "update").
  2. If you only need connection arguments (no remote command), call spec.Args(...) instead.
  3. Guard the call site: only invoke Command when you have a non-empty command to run.

Example fix

// before
args, err := spec.Command([]string{"-o", "StrictHostKeyChecking=no"})
// after
args, err := spec.Command([]string{"-o", "StrictHostKeyChecking=no"}, "docker", "system", "dial-stdio")
Defensive patterns

Strategy: validation

Validate before calling

if len(remoteCmd) == 0 {
    args, err := spec.Args(sshFlags...) // use Args when no command
} else {
    args, err := spec.Command(sshFlags, remoteCmd...)
}

Type guard

func hasRemoteCommand(cmd []string) bool { return len(cmd) > 0 }

Prevention

When it happens

Trigger: Calling spec.Command(sshFlags) with no variadic command arguments, or passing an empty slice. Using Command where Args was intended.

Common situations: A caller wires up Command for a dialer that only needs the connection arguments and forgets to supply the remote command. Misreading the API and assuming sshFlags are the command.

Related errors


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

Appendix: source

Thrown at cli/connhelper/ssh/ssh.go:148

	if err != nil {
		return nil, fmt.Errorf("invalid host: %w", err)
	}

	return append(args, "--", host), nil
}

// Command returns the ssh flags and arguments to execute a command
// (remoteCommandAndArgs) on the remote host. Where needed, it quotes
// values passed in remoteCommandAndArgs to account for ssh executing
// the remote command in a shell. It returns an error if no remote command
// is passed, or when unable to quote the remote command.
//
// Important: to preserve backward-compatibility, Command does not currently
// perform sanitization or quoting on the sshFlags and callers are expected
// to sanitize this argument.
func (sp *Spec) Command(sshFlags []string, remoteCommandAndArgs ...string) ([]string, error) {
	if len(remoteCommandAndArgs) == 0 {
		return nil, errors.New("no remote command specified")
	}
	sshArgs, err := sp.args(sshFlags...)
	if err != nil {
		return nil, err
	}
	remoteCommand, err := quoteCommand(remoteCommandAndArgs...)
	if err != nil {
		return nil, err
	}
	if remoteCommand != "" {
		sshArgs = append(sshArgs, remoteCommand)
	}
	return sshArgs, nil
}

// quoteCommand returns the remote command to run using the ssh connection
// as a single string, quoting values where needed because ssh executes
// these in a POSIX shell.

View on GitHub (pinned to 4f84911bfe)