@echo off setlocal EnableDelayedExpansion cd /d "%~dp0.." if not defined TARGET_INSTANCE_ID ( echo TARGET_INSTANCE_ID is required 1>&2 exit /b 2 ) set "containers=" for /f "delims=" %%C in ('docker compose ps --all --quiet api') do ( set "containers=!containers! %%C" set "candidate=%%C" rem This Compose uses Docker's default hostname: the first 12 container-ID characters. if "!candidate:~0,12!"=="%TARGET_INSTANCE_ID%" ( docker stop --time 0 %%C >nul if errorlevel 1 exit /b 1 exit /b 0 ) ) if not defined containers ( echo No API containers found 1>&2 exit /b 2 ) rem Fallback for explicitly configured hostnames, still scoped to this project's API containers. for /f "tokens=1,2 delims=:" %%H in ('docker inspect --format "{{.Config.Hostname}}:{{.Id}}" !containers!') do ( if "%%H"=="%TARGET_INSTANCE_ID%" ( rem Failure injection: stop immediately, leaving time for recovery within the 10-second test budget. docker stop --time 0 %%I >nul if errorlevel 1 exit /b 1 exit /b 0 ) ) echo No API container matches X-Instance-Id 1>&2 exit /b 2