# Corrected Blockscout Fix Commands

## Issues Found
1. Container is not running, so can't use `--network container:$BLOCKSCOUT_CONTAINER`
2. System uses `docker-compose` (with hyphen) not `docker compose`
3. Need to use postgres container's network instead

## Corrected Commands (Run in VMID 5000)

### Step 1: Run Migrations Using Postgres Network

```bash
# Get postgres container network
POSTGRES_NETWORK=$(docker inspect blockscout-postgres | grep -A 20 "Networks" | grep -oP '"NetworkID": "\K[^"]+' | head -1)

# Or use the network name directly
NETWORK_NAME=$(docker inspect blockscout-postgres -f '{{range $key, $value := .NetworkSettings.Networks}}{{$key}}{{end}}')

# Run migrations using postgres network
docker run --rm \
  --network $NETWORK_NAME \
  -e DATABASE_URL=postgresql://blockscout:blockscout@blockscout-postgres:5432/blockscout \
  blockscout/blockscout:latest \
  bin/blockscout eval "Explorer.Release.migrate()"
```

### Step 2: Alternative - Use Docker Network Bridge

```bash
# Find the bridge network
BRIDGE_NETWORK=$(docker network ls | grep bridge | awk '{print $1}' | head -1)

# Run migrations
docker run --rm \
  --network $BRIDGE_NETWORK \
  --add-host=postgres:$(docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' blockscout-postgres) \
  -e DATABASE_URL=postgresql://blockscout:blockscout@postgres:5432/blockscout \
  blockscout/blockscout:latest \
  bin/blockscout eval "Explorer.Release.migrate()"
```

### Step 3: Simplest - Use Host Network

```bash
# Use host network and connect to localhost
docker run --rm \
  --network host \
  -e DATABASE_URL=postgresql://blockscout:blockscout@localhost:5432/blockscout \
  blockscout/blockscout:latest \
  bin/blockscout eval "Explorer.Release.migrate()"
```

### Step 4: Update docker-compose.yml (Use docker-compose with hyphen)

```bash
cd /opt/blockscout  # or wherever docker-compose.yml is

# Backup
cp docker-compose.yml docker-compose.yml.backup

# Update command - check current command first
grep -A 2 "command:" docker-compose.yml

# Update to run migrations before start
sed -i 's|command:.*blockscout start|command: sh -c "bin/blockscout eval '\''Explorer.Release.migrate()'\'' \&\& bin/blockscout start"|' docker-compose.yml
sed -i 's|command:.*/app/bin/blockscout start|command: sh -c "bin/blockscout eval '\''Explorer.Release.migrate()'\'' \&\& bin/blockscout start"|' docker-compose.yml
```

### Step 5: Restart Using docker-compose (with hyphen)

```bash
cd /opt/blockscout
docker-compose down blockscout
docker-compose up -d blockscout

# Wait and check
sleep 30
docker ps | grep blockscout
docker logs blockscout 2>&1 | tail -20
```

## Complete One-Line Fix

```bash
# Run migrations using host network
docker run --rm --network host -e DATABASE_URL=postgresql://blockscout:blockscout@localhost:5432/blockscout blockscout/blockscout:latest bin/blockscout eval "Explorer.Release.migrate()" && \
cd /opt/blockscout && \
sed -i 's|command:.*blockscout start|command: sh -c "bin/blockscout eval '\''Explorer.Release.migrate()'\'' \&\& bin/blockscout start"|' docker-compose.yml && \
docker-compose restart blockscout
```

