Skip to content

Commit cd91586

Browse files
committed
Fix container conflict errors - Force remove existing containers
- Force remove existing containers (ml_churn_api, mlflow_server) before deployment - Use docker-compose down --remove-orphans to clean up properly - Add cleanup step in Test Docker container to remove ml-api-test - Stop and remove any containers using port 8000 before testing - Prevents 'container name already in use' and 'port already allocated' errors
1 parent e315ed2 commit cd91586

1 file changed

Lines changed: 26 additions & 3 deletions

File tree

.github/workflows/cd.yml

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,18 @@ jobs:
442442
run: |
443443
Write-Host "=== Testing Docker Container ==="
444444
445+
# Clean up any existing test containers and containers using port 8000
446+
Write-Host "Cleaning up existing test containers..."
447+
docker rm -f ml-api-test 2>&1 | Out-Null
448+
449+
# Stop any containers using port 8000
450+
$containersOnPort = docker ps --filter "publish=8000" --format "{{.Names}}" 2>&1
451+
if ($containersOnPort) {
452+
Write-Host "Stopping containers on port 8000: $containersOnPort"
453+
docker stop $containersOnPort 2>&1 | Out-Null
454+
docker rm $containersOnPort 2>&1 | Out-Null
455+
}
456+
445457
# Start container
446458
Write-Host "Starting Docker container..."
447459
docker run -d `
@@ -610,9 +622,20 @@ jobs:
610622
}
611623
Write-Host "Docker daemon is accessible - proceeding with deployment"
612624
613-
# Stop existing containers
614-
Write-Host "`nStopping existing containers..."
615-
$null = docker-compose down 2>&1
625+
# Force remove any existing containers with same names
626+
Write-Host "\nCleaning up existing containers..."
627+
$existingContainers = @('ml_churn_api', 'mlflow_server')
628+
foreach ($container in $existingContainers) {
629+
$exists = docker ps -a --filter "name=^/${container}$" --format "{{.Names}}" 2>&1
630+
if ($exists -eq $container) {
631+
Write-Host "Removing existing container: $container"
632+
docker rm -f $container 2>&1 | Out-Null
633+
}
634+
}
635+
636+
# Stop and remove docker-compose services
637+
Write-Host "Stopping docker-compose services..."
638+
$null = docker-compose down --remove-orphans 2>&1
616639
617640
# Start services
618641
Write-Host "Starting services with docker-compose..."

0 commit comments

Comments
 (0)