import subprocess
import shutil

def check_docker():
    """
    Checks if Docker is installed and running.
    Returns: (bool, str) - (Success, Message)
    """
    if not shutil.which("docker"):
        return False, "Docker is not installed"
    
    try:
        # 'docker info' returns 0 if daemon is running
        process = subprocess.run(
            ["docker", "info"], 
            stdout=subprocess.DEVNULL, 
            stderr=subprocess.DEVNULL,
            timeout=5
        )
        if process.returncode == 0:
            return True, "Docker is running"
        else:
            return False, "Docker daemon is not running"
    except subprocess.TimeoutExpired:
        return False, "Docker info command timed out (daemon might be unresponsive)"
    except Exception as e:
        return False, f"Error checking Docker: {str(e)}"
