Spaces:
Configuration error

README / openhands /runtime /impl /docker /containers.py
gauravanu001's picture
upload
2d63f96 verified
Raw History Blame Contribute Delete
551 Bytes
import docker
def stop_all_containers(prefix: str):
docker_client = docker.from_env()
try:
containers = docker_client.containers.list(all=True)
for container in containers:
try:
if 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()