#!/bin/bash # Quick DNS fix for WSL2 Docker connectivity issues # This is a simpler alternative that doesn't require root set -e echo "==========================================" echo "Quick Docker DNS Fix for WSL2" echo "==========================================" # Method 1: Fix WSL2 resolv.conf (requires sudo but is quick) echo "" echo "Method 1: Fixing WSL2 DNS configuration..." if [ "$EUID" -eq 0 ]; then # Running as root if [ -f /etc/resolv.conf ]; then cp /etc/resolv.conf /etc/resolv.conf.backup.$(date +%Y%m%d_%H%M%S) fi cat > /etc/resolv.conf < /etc/resolv.conf'" fi # Method 2: Test DNS resolution echo "" echo "Method 2: Testing DNS resolution..." if nslookup registry-1.docker.io > /dev/null 2>&1 || host registry-1.docker.io > /dev/null 2>&1; then echo "✓ DNS resolution working!" else echo "⚠ DNS resolution still failing" echo "Try: ping 8.8.8.8 to test basic connectivity" fi # Method 3: Docker Desktop specific fix echo "" echo "Method 3: Docker Desktop Configuration" echo "If using Docker Desktop, configure DNS in Docker Desktop settings:" echo " 1. Open Docker Desktop" echo " 2. Go to Settings > Resources > Network" echo " 3. Or Settings > Docker Engine" echo " 4. Add DNS configuration:" echo ' {' echo ' "dns": ["8.8.8.8", "8.8.4.4", "1.1.1.1"]' echo ' }' echo " 5. Click 'Apply & Restart'" # Method 4: Alternative - use Docker's built-in DNS echo "" echo "Method 4: Testing Docker with explicit DNS..." if command -v docker &> /dev/null; then echo "Testing Docker connectivity..." # Try to pull a small image to test if docker pull alpine:latest > /dev/null 2>&1; then echo "✓ Docker connectivity working!" else echo "⚠ Docker pull failed. This might indicate network issues." echo "" echo "Alternative solutions:" echo "1. Restart Docker Desktop" echo "2. Restart WSL: wsl --shutdown (from Windows PowerShell)" echo "3. Check Windows firewall/antivirus" echo "4. Try using a VPN or different network" fi fi echo "" echo "==========================================" echo "Quick fix completed!" echo "==========================================" echo "" echo "If issues persist, try the full fix: sudo ./fix-docker-dns.sh" echo ""