From f184b2bbfb26ed3bf2c98047a23539e8d6dc351c Mon Sep 17 00:00:00 2001 From: Beck Bekmyradov <47065940+bekmuradov@users.noreply.github.com> Date: Sat, 11 Oct 2025 17:15:14 +0400 Subject: [PATCH] fix(docker): make service installation idempotent to avoid container name conflicts - Added `docker compose down --remove-orphans` before build/start - Appended `--force-recreate` to start command to ensure clean container recreation - Prevents container name conflicts when re-importing plugins multiple times - Keeps other running plugin containers intact by scoping to per-plugin directory --- backend/app/plugins/service_installler/docker_manager.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/backend/app/plugins/service_installler/docker_manager.py b/backend/app/plugins/service_installler/docker_manager.py index 419d246..9352e4c 100644 --- a/backend/app/plugins/service_installler/docker_manager.py +++ b/backend/app/plugins/service_installler/docker_manager.py @@ -113,10 +113,16 @@ async def build_and_start_docker_service( # Write environment file write_env_file(target_dir, env_vars, required_vars) + # Clean up previous containers to avoid name conflicts + await _run_docker_compose_command("docker compose down --remove-orphans", target_dir) + # Rnu the docker compose build command await _run_docker_compose_command(install_command, target_dir) # Run the docker compose run command + # Start containers with force recreate + if "up" in start_command and "--force-recreate" not in start_command: + start_command += " --force-recreate" await _run_docker_compose_command(start_command, target_dir) # Wait for the service to become healthy