mirror of
https://github.com/OpenHands/OpenHands.git
synced 2025-12-26 05:48:36 +08:00
20 lines
578 B
Python
20 lines
578 B
Python
import docker
|
|
|
|
|
|
def stop_all_containers(prefix: str) -> None:
|
|
docker_client = docker.from_env()
|
|
try:
|
|
containers = docker_client.containers.list(all=True)
|
|
for container in containers:
|
|
try:
|
|
if container.name and container.name.startswith(prefix):
|
|
container.stop()
|
|
except docker.errors.APIError:
|
|
pass
|
|
except docker.errors.NotFound:
|
|
pass
|
|
except docker.errors.NotFound: # yes, this can happen!
|
|
pass
|
|
finally:
|
|
docker_client.close()
|