136 lines
3.9 KiB
Bash
Executable File
136 lines
3.9 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# Fix Docker DNS resolution issues in WSL2
|
|
# This script addresses the "dial tcp: lookup registry-1.docker.io" error
|
|
|
|
set -e
|
|
|
|
echo "=========================================="
|
|
echo "Docker DNS Fix for WSL2"
|
|
echo "=========================================="
|
|
|
|
# Check if running as root
|
|
if [ "$EUID" -ne 0 ]; then
|
|
echo "Please run as root or with sudo"
|
|
echo "Usage: sudo ./fix-docker-dns.sh"
|
|
exit 1
|
|
fi
|
|
|
|
# Step 1: Fix WSL2 DNS resolution
|
|
echo ""
|
|
echo "Step 1: Configuring WSL2 DNS..."
|
|
if [ ! -f /etc/wsl.conf ]; then
|
|
echo "Creating /etc/wsl.conf..."
|
|
cat > /etc/wsl.conf <<EOF
|
|
[network]
|
|
generateResolvConf = false
|
|
EOF
|
|
fi
|
|
|
|
# Backup existing resolv.conf
|
|
if [ -f /etc/resolv.conf ]; then
|
|
cp /etc/resolv.conf /etc/resolv.conf.backup.$(date +%Y%m%d_%H%M%S)
|
|
fi
|
|
|
|
# Create new resolv.conf with reliable DNS servers
|
|
echo "Updating /etc/resolv.conf with reliable DNS servers..."
|
|
cat > /etc/resolv.conf <<EOF
|
|
# DNS configuration for WSL2
|
|
# Generated by fix-docker-dns.sh
|
|
|
|
nameserver 8.8.8.8
|
|
nameserver 8.8.4.4
|
|
nameserver 1.1.1.1
|
|
nameserver 10.255.255.254
|
|
EOF
|
|
|
|
chattr +i /etc/resolv.conf 2>/dev/null || echo "Note: chattr not available, resolv.conf may be regenerated"
|
|
|
|
# Step 2: Configure Docker daemon DNS
|
|
echo ""
|
|
echo "Step 2: Configuring Docker daemon DNS..."
|
|
|
|
# Check if Docker Desktop is being used (common in WSL2)
|
|
if command -v docker &> /dev/null; then
|
|
DOCKER_CONTEXT=$(docker context show 2>/dev/null || echo "default")
|
|
echo "Docker context: $DOCKER_CONTEXT"
|
|
fi
|
|
|
|
# Create Docker daemon.json directory if it doesn't exist
|
|
mkdir -p /etc/docker
|
|
|
|
# Backup existing daemon.json if it exists
|
|
if [ -f /etc/docker/daemon.json ]; then
|
|
cp /etc/docker/daemon.json /etc/docker/daemon.json.backup.$(date +%Y%m%d_%H%M%S)
|
|
echo "Backed up existing daemon.json"
|
|
fi
|
|
|
|
# Create or update daemon.json with DNS configuration
|
|
echo "Creating/updating /etc/docker/daemon.json..."
|
|
cat > /etc/docker/daemon.json <<EOF
|
|
{
|
|
"dns": ["8.8.8.8", "8.8.4.4", "1.1.1.1"],
|
|
"log-driver": "json-file",
|
|
"log-opts": {
|
|
"max-size": "10m",
|
|
"max-file": "3"
|
|
}
|
|
}
|
|
EOF
|
|
|
|
# Step 3: Restart Docker service (if systemd is available)
|
|
echo ""
|
|
echo "Step 3: Restarting Docker service..."
|
|
if systemctl is-active --quiet docker 2>/dev/null; then
|
|
echo "Restarting Docker daemon..."
|
|
systemctl restart docker
|
|
echo "Waiting for Docker to be ready..."
|
|
sleep 5
|
|
elif command -v docker &> /dev/null; then
|
|
echo "Docker Desktop detected. Please restart Docker Desktop manually."
|
|
echo "Or run: wsl --shutdown (from Windows PowerShell) and restart WSL"
|
|
fi
|
|
|
|
# Step 4: Test DNS resolution
|
|
echo ""
|
|
echo "Step 4: Testing DNS resolution..."
|
|
echo "Testing registry-1.docker.io resolution..."
|
|
if nslookup registry-1.docker.io > /dev/null 2>&1; then
|
|
echo "✓ DNS resolution working!"
|
|
else
|
|
echo "⚠ DNS resolution still failing. Trying alternative approach..."
|
|
# Try with dig if available
|
|
if command -v dig &> /dev/null; then
|
|
dig registry-1.docker.io +short || echo "Still failing"
|
|
fi
|
|
fi
|
|
|
|
# Step 5: Test Docker connectivity
|
|
echo ""
|
|
echo "Step 5: Testing Docker connectivity..."
|
|
if command -v docker &> /dev/null; then
|
|
echo "Testing Docker pull (dry-run)..."
|
|
if docker pull hello-world:latest > /dev/null 2>&1; then
|
|
echo "✓ Docker connectivity working!"
|
|
else
|
|
echo "⚠ Docker pull test failed. This might be normal if images are already cached."
|
|
fi
|
|
fi
|
|
|
|
echo ""
|
|
echo "=========================================="
|
|
echo "Fix completed!"
|
|
echo "=========================================="
|
|
echo ""
|
|
echo "Next steps:"
|
|
echo "1. If using Docker Desktop, restart it from Windows"
|
|
echo "2. Or restart WSL: wsl --shutdown (from Windows PowerShell)"
|
|
echo "3. Try running your Quorum network again: ./run.sh"
|
|
echo ""
|
|
echo "If issues persist, try:"
|
|
echo " - Check Windows firewall settings"
|
|
echo " - Verify internet connectivity"
|
|
echo " - Check Docker Desktop settings for network configuration"
|
|
echo ""
|
|
|