How to use the aiodocker.docker.DockerContainer function in aiodocker

To help you get started, we’ve selected a few aiodocker examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github lablup / backend.ai-agent / src / ai / backend / agent / utils.py View on Github external
async def get_kernel_id_from_container(val: Union[str, DockerContainer]) -> Optional[KernelId]:
    if isinstance(val, DockerContainer):
        if 'Name' not in val._container:
            await val.show()
        name = val['Name']
    elif isinstance(val, str):
        name = val
    name = name.lstrip('/')
    if not name.startswith('kernel.'):
        return None
    try:
        return KernelId(UUID(name.rsplit('.', 2)[-1]))
    except (IndexError, ValueError):
        return None
github lablup / backend.ai-agent / src / ai / backend / agent / docker / intrinsic.py View on Github external
async def api_impl(container_id):
            try:
                container = DockerContainer(ctx.agent.docker, id=container_id)
                ret = await container.stats(stream=False)  # TODO: cache
            except RuntimeError as e:
                msg = str(e.args[0]).lower()
                if 'event loop is closed' in msg or 'session is closed' in msg:
                    return None
                raise
            except (DockerError, aiohttp.ClientError):
                short_cid = container._id[:7]
                log.warning(f'cannot read stats: Docker stats API error for {short_cid}.')
                return None
            else:
                # API returned successfully but actually the result may be empty!
                if ret is None or not isinstance(ret, dict):
                    return None
                if ret['preread'].startswith('0001-01-01'):
                    return None