Skip to content

cmd/docker: fail on unknown command with --version - #7408

Merged
vvoland merged 1 commit into
docker:masterfrom
GitNimay:3833-unknown-command-version-flag
Oct 19, 2026
Merged

vvoland merged 1 commit into
docker:masterfrom
GitNimay:3833-unknown-command-version-flag

Conversation

@GitNimay

@GitNimay GitNimay commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

Summary

docker nonexistent --version printed the CLI version and exited 0, so it couldn't be used to check whether a command or plugin (for example docker compose) is installed. Without --version the same invocation fails with unknown command.

When no built-in command or plugin matches, runDocker falls through to executing the root command. Cobra handles --version before the root command's RunE reports the unknown command. This PR unsets the root command's Version in that fallback, so the standard unknown-command error is returned. Plugin hooks still run, since the normal execution path is unchanged.

Before:

$ docker nonexistent --version
Docker version 29.x, build xxxxxxx
$ echo $?
0

After:

$ docker nonexistent --version
docker: unknown command: docker nonexistent

Run 'docker --help' for more information
$ echo $?
1

Unchanged:

  • docker --version / docker -v still print the version, including when --version is passed as a global flag before an unknown argument (docker --version foo, covered by TestCliPluginsVersion).
  • docker nonexistent --help still prints the top-level help (covered by TestNonexistingHelp).
  • Installed plugins still handle their own --version (e.g. docker compose --version).

Added TestNonexistingVersion to e2e/cli-plugins, covering both --version and -v.

Release notes (optional)

Fix `docker <unknown-command> --version` printing the CLI version instead of an "unknown command" error.

vvoland
vvoland previously approved these changes Oct 19, 2026
@vvoland vvoland added this to the 29.10.0 milestone Oct 19, 2026
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@vvoland

vvoland commented Oct 19, 2026

Copy link
Copy Markdown
Collaborator

Please squash into one commit

Running "docker nonexistent --version" printed the CLI version and
exited 0, so it couldn't be used to check whether a command or plugin
is available. Without "--version" the same invocation fails with an
"unknown command" error.

When no built-in command or plugin matches, runDocker falls through to
executing the root command, and cobra handles the "--version" flag
before the root command reports the unknown command. Unset the root
command's version in that fallback, so the standard unknown-command
error is returned.

A global "--version" flag ("docker --version nonexistent") is parsed
before the command name and still prints the version, as do
"docker --version" and "docker nonexistent --help".

Signed-off-by: Nimesh Kulkarni <167794819+GitNimay@users.noreply.github.com>
@GitNimay
GitNimay force-pushed the 3833-unknown-command-version-flag branch from b1fcfb6 to e08aa72 Compare October 19, 2026 14:09
@GitNimay

Copy link
Copy Markdown
Contributor Author

@vvoland Done, squashed into one commit (e08aa72). The content is unchanged.

@vvoland

vvoland commented Oct 19, 2026

Copy link
Copy Markdown
Collaborator

Thanks!

@vvoland
vvoland merged commit 6f83690 into docker:master Oct 19, 2026
99 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

docker doesn't error out on docker missing-subcommand --version

3 participants