@@ -14,6 +14,16 @@ Write-Host "Pulling image: $image"
1414docker pull $image
1515if ($LASTEXITCODE -ne 0 ) { throw " docker pull failed with exit code $LASTEXITCODE " }
1616
17+ Write-Host " Checking for existing container named $containerName ..."
18+ $existingContainerId = docker ps - a -- filter " name=^${containerName} $" -- format ' {{.ID}}'
19+ if ($LASTEXITCODE -ne 0 ) { throw " docker ps failed with exit code $LASTEXITCODE " }
20+ if ($existingContainerId ) {
21+ Write-Host " Existing container '$containerName ' found. Stopping and removing it..."
22+ docker stop $containerName 2> $null
23+ docker rm -f $containerName
24+ if ($LASTEXITCODE -ne 0 ) { throw " docker rm failed with exit code $LASTEXITCODE " }
25+ }
26+
1727# -t is required because Start.ps1 sets [Console]::BufferWidth which needs a TTY handle.
1828Write-Host " Starting Cosmos DB Emulator container on port $port ..."
1929docker run - d - t `
@@ -27,14 +37,11 @@ Write-Host "Waiting for emulator to be ready (up to $($maxRetries * $retryDelayS
2737$ready = $false
2838for ($i = 0 ; $i -lt $maxRetries ; $i ++ ) {
2939 Start-Sleep - Seconds $retryDelaySec
30- try {
31- # Any HTTP response (even 401) means the emulator is up and accepting connections.
32- $null = Invoke-WebRequest - Uri " https://localhost:${port} /" - UseBasicParsing - TimeoutSec 5
33- $ready = $true
34- } catch [Microsoft.PowerShell.Commands.HttpResponseException ] {
35- # Got an HTTP error response (401, 404, etc.) — emulator is reachable.
40+ # Any HTTP response (even 401) means the emulator is up and accepting connections.
41+ $null = & curl.exe - k " https://localhost:${port} /" -- silent -- output NUL -- max- time 5
42+ if ($LASTEXITCODE -eq 0 ) {
3643 $ready = $true
37- } catch {
44+ } else {
3845 Write-Host " Attempt $ ( $i + 1 ) /$maxRetries - not ready yet..."
3946 }
4047 if ($ready ) {
0 commit comments