MCPcopy Index your code
hub / github.com/agent0ai/agent-zero / start_container

Method start_container

helpers/docker.py:65–99  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

63 return infos
64
65 def start_container(self) -> None:
66 if not self.client: self.client = self.init_docker()
67 existing_container = None
68 for container in self.client.containers.list(all=True):
69 if container.name == self.name:
70 existing_container = container
71 break
72
73 if existing_container:
74 if existing_container.status != 'running':
75 PrintStyle.standard(f"Starting existing container: {self.name} for safe code execution...")
76 if self.logger: self.logger.log(type="info", content=f"Starting existing container: {self.name} for safe code execution...")
77
78 existing_container.start()
79 self.container = existing_container
80 time.sleep(2) # this helps to get SSH ready
81
82 else:
83 self.container = existing_container
84 # PrintStyle.standard(f"Container with name '{self.name}' is already running with ID: {existing_container.id}")
85 else:
86 PrintStyle.standard(f"Initializing docker container {self.name} for safe code execution...")
87 if self.logger: self.logger.log(type="info", content=f"Initializing docker container {self.name} for safe code execution...")
88
89 self.container = self.client.containers.run(
90 self.image,
91 detach=True,
92 ports=self.ports, # type: ignore
93 name=self.name,
94 volumes=self.volumes, # type: ignore
95 )
96 # atexit.register(self.cleanup_container)
97 PrintStyle.standard(f"Started container with ID: {self.container.id}")
98 if self.logger: self.logger.log(type="info", content=f"Started container with ID: {self.container.id}")
99 time.sleep(5) # this helps to get SSH ready

Callers

nothing calls this directly

Calls 6

init_dockerMethod · 0.95
listMethod · 0.80
standardMethod · 0.80
logMethod · 0.45
startMethod · 0.45
runMethod · 0.45

Tested by

no test coverage detected