From 19a5c5c714f9237e028f90841811348a48378249 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Thu, 19 Jun 2025 15:40:58 +0200 Subject: [PATCH] remove undocumented top-level "docker remove" command This was introduced in 9b54d860cd8b131890b92e8591c6ddd650f4d340, which added `docker container remove` as alias for `docker container rm`. However, due to the `NewRmCommand` being used both for adding the top-level `docker rm` command and for adding the `docker container rm` command, it also introduced a (hidden) top-level `docker remove` command; docker remove --help | head -n1 Usage: docker rm [OPTIONS] CONTAINER [CONTAINER...] The command was not documented, and did not appear in `--help` output, nor was auto-complete provided; docker --help | grep remove docker r rename (Rename a container) rm (Remove one or more containers) run (Create and run a new container from an image) restart (Restart one or more containers) rmi (Remove one or more images) This patch adds a dedicated, non-exported `newRemoveCommand` to add sub- commands for `docker container`, taking a similar approach as was done in [moby@b993609d5a] for `docker image rm`. With this patch applied, the hidden command is no longer there, but the `docker rm`, `docker container rm`, and `docker container remove` commands stay functional as intended; docker remove foo docker: unknown command: docker remove Run 'docker --help' for more information docker rm --help | head -n1 Usage: docker rm [OPTIONS] CONTAINER [CONTAINER...] docker container rm --help | head -n1 Usage: docker container rm [OPTIONS] CONTAINER [CONTAINER...] docker container remove --help | head -n1 Usage: docker container rm [OPTIONS] CONTAINER [CONTAINER...] [moby@b993609d5a]: https://github.com/moby/moby/commit/b993609d5ad4590da72e217bb43786b74aabc183 Reported-by: Lorenzo Buero <138243046+LorenzoBuero@users.noreply.github.com> Co-authored-by: Lorenzo Buero <138243046+LorenzoBuero@users.noreply.github.com> Signed-off-by: Sebastiaan van Stijn --- cli/command/container/cmd.go | 2 +- cli/command/container/rm.go | 16 ++++++++++++---- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/cli/command/container/cmd.go b/cli/command/container/cmd.go index dcf8116ef1..4ff00e74b5 100644 --- a/cli/command/container/cmd.go +++ b/cli/command/container/cmd.go @@ -28,7 +28,7 @@ func NewContainerCommand(dockerCli command.Cli) *cobra.Command { NewPortCommand(dockerCli), NewRenameCommand(dockerCli), NewRestartCommand(dockerCli), - NewRmCommand(dockerCli), + newRemoveCommand(dockerCli), NewRunCommand(dockerCli), NewStartCommand(dockerCli), NewStatsCommand(dockerCli), diff --git a/cli/command/container/rm.go b/cli/command/container/rm.go index c36f523a5c..3206bb5992 100644 --- a/cli/command/container/rm.go +++ b/cli/command/container/rm.go @@ -27,10 +27,9 @@ func NewRmCommand(dockerCli command.Cli) *cobra.Command { var opts rmOptions cmd := &cobra.Command{ - Use: "rm [OPTIONS] CONTAINER [CONTAINER...]", - Aliases: []string{"remove"}, - Short: "Remove one or more containers", - Args: cli.RequiresMinArgs(1), + Use: "rm [OPTIONS] CONTAINER [CONTAINER...]", + Short: "Remove one or more containers", + Args: cli.RequiresMinArgs(1), RunE: func(cmd *cobra.Command, args []string) error { opts.containers = args return runRm(cmd.Context(), dockerCli, &opts) @@ -50,6 +49,15 @@ func NewRmCommand(dockerCli command.Cli) *cobra.Command { return cmd } +// newRemoveCommand adds subcommands for "docker container"; unlike the +// top-level "docker rm", it also adds a "remove" alias to support +// "docker container remove" in addition to "docker container rm". +func newRemoveCommand(dockerCli command.Cli) *cobra.Command { + cmd := *NewRmCommand(dockerCli) + cmd.Aliases = []string{"rm", "remove"} + return &cmd +} + func runRm(ctx context.Context, dockerCLI command.Cli, opts *rmOptions) error { apiClient := dockerCLI.Client() errChan := parallelOperation(ctx, opts.containers, func(ctx context.Context, ctrID string) error {