Find the docker executable on the system. Returns: Path to docker executable, or None if not found
()
| 18 | |
| 19 | |
| 20 | def find_docker_executable() -> Optional[str]: |
| 21 | """Find the docker executable on the system. |
| 22 | |
| 23 | Returns: |
| 24 | Path to docker executable, or None if not found |
| 25 | """ |
| 26 | global _docker_executable_cache |
| 27 | |
| 28 | if _docker_executable_cache is not None: |
| 29 | return _docker_executable_cache |
| 30 | |
| 31 | # Check if docker command is available |
| 32 | try: |
| 33 | result = RunningProcess.run( |
| 34 | ["docker", "--version"], |
| 35 | cwd=None, |
| 36 | check=False, |
| 37 | timeout=5, |
| 38 | ) |
| 39 | if result.returncode == 0: |
| 40 | _docker_executable_cache = "docker" |
| 41 | return "docker" |
| 42 | except (FileNotFoundError, RuntimeError): |
| 43 | pass |
| 44 | |
| 45 | # On Windows, try to find docker.exe in common locations |
| 46 | if sys.platform == "win32": |
| 47 | common_paths = [ |
| 48 | r"C:\Program Files\Docker\Docker\resources\bin\docker.exe", |
| 49 | r"C:\Program Files\Docker\Docker\docker.exe", |
| 50 | ] |
| 51 | for path in common_paths: |
| 52 | if os.path.exists(path): |
| 53 | _docker_executable_cache = path |
| 54 | return path |
| 55 | |
| 56 | return None |
| 57 | |
| 58 | |
| 59 | def get_docker_command() -> str: |
no test coverage detected