mirror of
https://github.com/containers/podman-compose.git
synced 2024-11-21 15:33:15 +01:00
Add --remove-orphans on down command
Signed-off-by: Sander Hoentjen <shoentjen@antagonist.nl>
This commit is contained in:
parent
e84451f4ea
commit
b4c0792995
@ -98,7 +98,7 @@ _completeExecArgs() {
|
||||
|
||||
# complete the arguments for `podman-compose down` and return 0
|
||||
_completeDownArgs() {
|
||||
down_opts="${help_opts} -v --volumes -t --timeout"
|
||||
down_opts="${help_opts} -v --volumes -t --timeout --remove-orphans"
|
||||
if [[ ${prev} == "-t" || ${prev} == "--timeout" ]]; then
|
||||
return 0
|
||||
elif [[ ${cur} == -* ]]; then
|
||||
|
@ -2141,6 +2141,26 @@ def compose_down(compose, args):
|
||||
if cnt["_service"] in excluded:
|
||||
continue
|
||||
compose.podman.run([], "rm", [cnt["name"]], sleep=0)
|
||||
if args.remove_orphans:
|
||||
names = (
|
||||
compose.podman.output(
|
||||
[],
|
||||
"ps",
|
||||
[
|
||||
"--filter",
|
||||
f"label=io.podman.compose.project={compose.project_name}",
|
||||
"-a",
|
||||
"--format",
|
||||
"{{ .Names }}",
|
||||
],
|
||||
)
|
||||
.decode("utf-8")
|
||||
.splitlines()
|
||||
)
|
||||
for name in names:
|
||||
compose.podman.run([], "stop", [*podman_args, name], sleep=0)
|
||||
for name in names:
|
||||
compose.podman.run([], "rm", [name], sleep=0)
|
||||
if args.volumes:
|
||||
vol_names_to_keep = set()
|
||||
for cnt in containers:
|
||||
@ -2564,6 +2584,11 @@ def compose_down_parse(parser):
|
||||
help="Remove named volumes declared in the `volumes` section of the Compose file and "
|
||||
"anonymous volumes attached to containers.",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--remove-orphans",
|
||||
action="store_true",
|
||||
help="Remove containers for services not defined in the Compose file.",
|
||||
)
|
||||
|
||||
|
||||
@cmd_parse(podman_compose, "run")
|
||||
|
Loading…
Reference in New Issue
Block a user