Skip to content

Conversation

@thaJeztah
Copy link
Member

@thaJeztah thaJeztah commented Jun 19, 2025

This was introduced in 9b54d86, 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<TAB>
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...]

Reported-by: Lorenzo Buero [email protected]

- What I did

- How I did it

- How to verify it

- Human readable description for the release notes

Remove an undocumented, hidden, top-level `docker remove` command that was accidentally introduced in Docker 23.0

- A picture of a cute animal (not mandatory but encouraged)

This was introduced in 9b54d86,
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<TAB>
    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]: moby/moby@b993609

Reported-by: Lorenzo Buero <[email protected]>
Co-authored-by: Lorenzo Buero <[email protected]>
Signed-off-by: Sebastiaan van Stijn <[email protected]>
@codecov-commenter
Copy link

codecov-commenter commented Jun 19, 2025

Codecov Report

Attention: Patch coverage is 37.50000% with 5 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
cli/command/container/rm.go 42.85% 4 Missing ⚠️
cli/command/container/cmd.go 0.00% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@AkihiroSuda AkihiroSuda merged commit 80d1959 into docker:master Jun 19, 2025
98 of 102 checks passed
@thaJeztah thaJeztah deleted the rm_top_level_remove branch June 20, 2025 06:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment