How to use the aiodocker.exceptions.DockerContainerError 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 aio-libs / aiodocker / tests / test_containers.py View on Github external
async def test_run_failing_start_container(docker):
    name = "python:latest"
    try:
        await docker.images.delete(name)
    except DockerError as e:
        if e.status == 404:
            pass  # already missing, pass
        else:
            raise

    with pytest.raises(DockerContainerError) as e_info:
        await docker.containers.run(
            config={
                # we want to raise an error
                # `executable file not found`
                "Cmd": ["pytohon", "-c" "print('hello')"],
                "Image": name,
            }
        )

    assert e_info.value.container_id
    # This container is created but not started!
    # We should delete it afterwards.
    cid = e_info.value.container_id
    container = docker.containers.container(cid)
    await container.delete()
github mushorg / tanner / tanner / utils / aiodocker_helper.py View on Github external
:param image (str): name of image to be used
        :return: container (object): newly created container object
        """
        await self.setup_host_image()
        container = None
        if image is None:
            image = self.host_image

        config = {
            "Cmd": cmd,
            "Image": image
        }
        try:
            container = await self.docker_client.containers.create_or_replace(config=config, name=container_name)

        except (aiodocker.exceptions.DockerError or aiodocker.exceptions.DockerContainerError) as docker_error:
            self.logger.exception('Error while creating a container %s', docker_error)
        return container
github aio-libs / aiodocker / aiodocker / containers.py View on Github external
a `container_id` attribute with the id of the container.
        """
        try:
            container = await self.create(config, name=name)
        except DockerError as err:
            # image not find, try pull it
            if err.status == 404 and "Image" in config:
                await self.docker.pull(config["Image"])
                container = await self.create(config, name=name)
            else:
                raise err

        try:
            await container.start()
        except DockerError as err:
            raise DockerContainerError(
                err.status, {"message": err.message}, container["id"]
            )

        return container
github lablup / backend.ai-agent / src / ai / backend / agent / docker / agent.py View on Github external
stats_monitor: StatsPluginContext,
        error_monitor: ErrorPluginContext,
        skip_initial_scan: bool = False,
    ) -> None:
        super().__init__(
            etcd,
            local_config,
            stats_monitor=stats_monitor,
            error_monitor=error_monitor,
            skip_initial_scan=skip_initial_scan,
        )

        # Monkey-patch pickling support for aiodocker exceptions
        # FIXME: remove if https://github.com/aio-libs/aiodocker/issues/442 is merged
        DockerError.__reduce__ = _DockerError_reduce                     # type: ignore
        DockerContainerError.__reduce__ = _DockerContainerError_reduce   # type: ignore