Skip to content

Commit 80d1959

Browse files
authored
Merge pull request #6144 from thaJeztah/rm_top_level_remove
remove undocumented top-level "docker remove" command
2 parents 747cb44 + 19a5c5c commit 80d1959

2 files changed

Lines changed: 13 additions & 5 deletions

File tree

cli/command/container/cmd.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ func NewContainerCommand(dockerCli command.Cli) *cobra.Command {
2828
NewPortCommand(dockerCli),
2929
NewRenameCommand(dockerCli),
3030
NewRestartCommand(dockerCli),
31-
NewRmCommand(dockerCli),
31+
newRemoveCommand(dockerCli),
3232
NewRunCommand(dockerCli),
3333
NewStartCommand(dockerCli),
3434
NewStatsCommand(dockerCli),

cli/command/container/rm.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,9 @@ func NewRmCommand(dockerCli command.Cli) *cobra.Command {
2727
var opts rmOptions
2828

2929
cmd := &cobra.Command{
30-
Use: "rm [OPTIONS] CONTAINER [CONTAINER...]",
31-
Aliases: []string{"remove"},
32-
Short: "Remove one or more containers",
33-
Args: cli.RequiresMinArgs(1),
30+
Use: "rm [OPTIONS] CONTAINER [CONTAINER...]",
31+
Short: "Remove one or more containers",
32+
Args: cli.RequiresMinArgs(1),
3433
RunE: func(cmd *cobra.Command, args []string) error {
3534
opts.containers = args
3635
return runRm(cmd.Context(), dockerCli, &opts)
@@ -50,6 +49,15 @@ func NewRmCommand(dockerCli command.Cli) *cobra.Command {
5049
return cmd
5150
}
5251

52+
// newRemoveCommand adds subcommands for "docker container"; unlike the
53+
// top-level "docker rm", it also adds a "remove" alias to support
54+
// "docker container remove" in addition to "docker container rm".
55+
func newRemoveCommand(dockerCli command.Cli) *cobra.Command {
56+
cmd := *NewRmCommand(dockerCli)
57+
cmd.Aliases = []string{"rm", "remove"}
58+
return &cmd
59+
}
60+
5361
func runRm(ctx context.Context, dockerCLI command.Cli, opts *rmOptions) error {
5462
apiClient := dockerCLI.Client()
5563
errChan := parallelOperation(ctx, opts.containers, func(ctx context.Context, ctrID string) error {

0 commit comments

Comments
 (0)