From 2b716e5d903131dca408191315c7ae3518b7de37 Mon Sep 17 00:00:00 2001 From: Kevin Veen-Birkenbach Date: Tue, 9 Jan 2024 12:59:53 +0100 Subject: [PATCH] Optimized code performance --- backup-docker-to-local.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/backup-docker-to-local.py b/backup-docker-to-local.py index 6385f96..908a166 100644 --- a/backup-docker-to-local.py +++ b/backup-docker-to-local.py @@ -165,18 +165,18 @@ def has_image(container,image): """Check if the container is using the image""" image_info = get_image_info(container) return image in image_info[0] - + def stop_containers(containers): """Stop a list of containers.""" - for container in containers: - print(f"Stopping container {container}...") - execute_shell_command(f"docker stop {container}") - + container_list = ' '.join(containers) + print(f"Stopping containers {container_list}...") + execute_shell_command(f"docker stop {container_list}") + def start_containers(containers): - """Start a list of stopped containers.""" - for container in containers: - print(f"Starting container {container}...") - execute_shell_command(f"docker start {container}") + """Start a list of containers.""" + container_list = ' '.join(containers) + print(f"Start containers {container_list}...") + execute_shell_command(f"docker start {container_list}") def get_container_with_image(containers,image): for container in containers: