"""Comprueba si un contenedor Docker está corriendo por nombre.""" from __future__ import annotations import subprocess def docker_container_running(name: str, timeout: float = 5.0) -> bool: """Devuelve True si el contenedor `name` existe y está corriendo. Usa `docker inspect -f '{{.State.Running}}' `. Cualquier fallo (docker no instalado, contenedor inexistente, daemon caído, timeout) se interpreta como False. """ try: proc = subprocess.run( ["docker", "inspect", "-f", "{{.State.Running}}", name], capture_output=True, text=True, timeout=timeout, ) except (FileNotFoundError, subprocess.TimeoutExpired, OSError): return False if proc.returncode != 0: return False return proc.stdout.strip().lower() == "true"