fix(deploy): force remove containers before deployment
The --force-recreate flag alone doesn't handle containers that exist outside the compose project context. Now explicitly: 1. Run docker compose down first 2. Force remove any orphaned containers with known names 3. Then create fresh containers
This commit is contained in:
@@ -117,10 +117,20 @@ fi
|
|||||||
print_info "Pulling latest images..."
|
print_info "Pulling latest images..."
|
||||||
docker compose $COMPOSE_FILES pull || print_warning "Failed to pull some images, continuing..."
|
docker compose $COMPOSE_FILES pull || print_warning "Failed to pull some images, continuing..."
|
||||||
|
|
||||||
|
# Stop and remove existing containers to prevent name conflicts
|
||||||
|
print_info "Stopping existing containers..."
|
||||||
|
docker compose $COMPOSE_FILES down --remove-orphans || print_warning "No existing containers to stop"
|
||||||
|
|
||||||
|
# Remove any orphaned containers with conflicting names
|
||||||
|
for container in nginx php redis scheduler queue-worker; do
|
||||||
|
if docker ps -a --format '{{.Names}}' | grep -q "^${container}$"; then
|
||||||
|
print_warning "Removing orphaned container: $container"
|
||||||
|
docker rm -f "$container" 2>/dev/null || true
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
# Deploy stack
|
# Deploy stack
|
||||||
print_info "Deploying application stack..."
|
print_info "Deploying application stack..."
|
||||||
# --force-recreate: Recreate containers even if unchanged
|
|
||||||
# --remove-orphans: Remove containers for services not in compose file
|
|
||||||
docker compose $COMPOSE_FILES up -d --force-recreate --remove-orphans
|
docker compose $COMPOSE_FILES up -d --force-recreate --remove-orphans
|
||||||
|
|
||||||
# Wait for services to be healthy
|
# Wait for services to be healthy
|
||||||
|
|||||||
Reference in New Issue
Block a user