(
self, image: str, port: int = 8000, remove: bool = True, **kwargs
)
| 51 | """ |
| 52 | |
| 53 | def __init__( |
| 54 | self, image: str, port: int = 8000, remove: bool = True, **kwargs |
| 55 | ): |
| 56 | super().__init__() |
| 57 | |
| 58 | import docker |
| 59 | |
| 60 | self.client = docker.from_env() |
| 61 | self.container: Optional[Container] = None |
| 62 | |
| 63 | api_path = Path(__file__).parent / "api.py" |
| 64 | self.mounts: Dict[Path, Path] = dict() |
| 65 | self.cp: Dict[Path, Path] = {api_path: Path("/home")} |
| 66 | self.entrypoint: Dict[str, str] = dict() |
| 67 | self.tasks: List[TaskConfig] = [] |
| 68 | |
| 69 | self.docker_config = kwargs |
| 70 | self.image = image |
| 71 | self.port = port if port > 0 else randint(10000, 20000) |
| 72 | self.remove = remove |
| 73 | |
| 74 | if not self.client.images.list(name=self.image): |
| 75 | logger.warning( |
| 76 | f"Image {self.image} not found. Pulling from Docker Hub." |
| 77 | ) |
| 78 | self.client.images.pull(self.image) |
| 79 | |
| 80 | def mount(self, path: str, mount_path: str) -> "DockerRuntime": |
| 81 | r"""Mount a local directory to the container. |
nothing calls this directly
no outgoing calls
no test coverage detected