From de6ca8dbe8d8078137126362749bddff155c4c4d Mon Sep 17 00:00:00 2001 From: Harald Albers Date: Thu, 10 Oct 2024 18:58:35 +0000 Subject: [PATCH] Only complete removable containers if --force is not given Signed-off-by: Harald Albers (cherry picked from commit 147630a3093c67625780b84ccb5b62fb7bbbc380) Signed-off-by: Sebastiaan van Stijn --- cli/command/container/rm.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/cli/command/container/rm.go b/cli/command/container/rm.go index 171e8e81e9e4..b234b6009874 100644 --- a/cli/command/container/rm.go +++ b/cli/command/container/rm.go @@ -8,6 +8,7 @@ import ( "github.com/docker/cli/cli" "github.com/docker/cli/cli/command" "github.com/docker/cli/cli/command/completion" + "github.com/docker/docker/api/types" "github.com/docker/docker/api/types/container" "github.com/docker/docker/errdefs" "github.com/pkg/errors" @@ -38,7 +39,9 @@ func NewRmCommand(dockerCli command.Cli) *cobra.Command { Annotations: map[string]string{ "aliases": "docker container rm, docker container remove, docker rm", }, - ValidArgsFunction: completion.ContainerNames(dockerCli, true), + ValidArgsFunction: completion.ContainerNames(dockerCli, true, func(ctr types.Container) bool { + return opts.force || ctr.State == "exited" || ctr.State == "created" + }), } flags := cmd.Flags()