当前位置: 首页>>代码示例>>Python>>正文


Python errors.ContainerError方法代码示例

本文整理汇总了Python中docker.errors.ContainerError方法的典型用法代码示例。如果您正苦于以下问题:Python errors.ContainerError方法的具体用法?Python errors.ContainerError怎么用?Python errors.ContainerError使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在docker.errors的用法示例。


在下文中一共展示了errors.ContainerError方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: runContainer

# 需要导入模块: from docker import errors [as 别名]
# 或者: from docker.errors import ContainerError [as 别名]
def runContainer(image, **kwargs):
    '''Run a docker container using a given image; passing keyword arguments
    documented to be accepted by docker's client.containers.run function
    No extra side effects. Handles and reraises ContainerError, ImageNotFound,
    and APIError exceptions.
    '''
    container = None
    try:
        container = client.containers.run(image, **kwargs)
        if "name" in kwargs.keys():
          print("Container", kwargs["name"], "is now running.")
    except ContainerError as exc:
        eprint("Failed to run container")
        raise exc
    except ImageNotFound as exc:
        eprint("Failed to find image to run as a docker container")
        raise exc
    except APIError as exc:
        eprint("Unhandled error")
        raise exc

    return container 
开发者ID:hyperledger,项目名称:indy-node,代码行数:24,代码来源:indypool.py

示例2: run

# 需要导入模块: from docker import errors [as 别名]
# 或者: from docker.errors import ContainerError [as 别名]
def run(self, verbose=True, log_file=None):
        # TODO(allenh1): add the ability to check out a non-master
        # branch of the overlay (for CI).
        info('testing gentoo package integrity')
        for pkg in sorted(self.package_list.keys()):
            self.container.add_bash_command('emaint sync -r ros-overlay')
            self.container.add_bash_command('emerge %s' % pkg)
            try:
                self.container.run(
                    rm=True, show_cmd=True, privileged=True, log_file=log_file
                )
                self.package_list[pkg] = 'building'
                ok("  '%s': building" % pkg)
            except ContainerError:
                self.package_list[pkg] = 'failing'
                err("  '%s': failing" % pkg)
            if verbose:
                print(self.container.log)
            self.container.clear_commands()
        return self.package_list 
开发者ID:ros-infrastructure,项目名称:superflore,代码行数:22,代码来源:build_base.py

示例3: latex2html

# 需要导入模块: from docker import errors [as 别名]
# 或者: from docker.errors import ContainerError [as 别名]
def latex2html(self, source_dir, output_dir, use_named_volumes=False):
        base = self._scripts_path
        source_dir = Path(source_dir)
        output_dir = Path(output_dir)
        scriptname = "/files/latex2html.sh"
        filename = "index.html"

        volumes = {
            base / "latex2html.sh": ro_bind("/files/latex2html.sh"),
            base / "guess_main.py": ro_bind("/files/guess_main.py"),  # todo: run guess_main outside of docker
            base / "patches": ro_bind("/files/patches")   # todo: see which patches can be dropped
        }

        # In case of fully dockerized pipeline we use named volumes to share files between the steps.
        # This, however, requires as to mount specific volumes with all papers, not only the currently processed one.
        # (see https://github.com/moby/moby/issues/32582)
        if use_named_volumes:
            volumes.update({
                "pwc_unpacked_sources": ro_bind("/data/arxiv/unpacked_sources"),
                "pwc_htmls": rw_bind("/data/arxiv/htmls")
            })
            command = [scriptname, filename, str(source_dir), str(output_dir)]
        else:
            volumes.update({
                source_dir.resolve(): ro_bind("/files/ro-source"),
                output_dir.resolve(): rw_bind("/files/htmls")
            })
            command = [scriptname, filename]

        output_dir.mkdir(parents=True, exist_ok=True)

        try:
            self.client.containers.run("arxivvanity/engrafo:b3db888fefa118eacf4f13566204b68ce100b3a6", command, remove=True, volumes=volumes)
        except ContainerError as err:
            if err.exit_status == MAGIC_EXIT_ERROR:
                raise LatexConversionError("LaTeXML was unable to convert source code of this paper")
            if "Unable to find any suitable tex file" in err.stderr.decode('utf-8'):
                raise LatexConversionError("Unable to find any suitable tex file")
            raise

    # todo: check for errors 
开发者ID:paperswithcode,项目名称:axcell,代码行数:43,代码来源:latex_converter.py

示例4: to_html

# 需要导入模块: from docker import errors [as 别名]
# 或者: from docker.errors import ContainerError [as 别名]
def to_html(self, source_dir):
        with TemporaryDirectory() as output_dir:
            output_dir = Path(output_dir)
            try:
                self.latex2html(source_dir, output_dir)
                return self.clean_html(output_dir / "index.html")
            except ContainerError as err:
                raise LatexConversionError from err 
开发者ID:paperswithcode,项目名称:axcell,代码行数:10,代码来源:latex_converter.py

示例5: _testDockerPipeChainErrorFn

# 需要导入模块: from docker import errors [as 别名]
# 或者: from docker.errors import ContainerError [as 别名]
def _testDockerPipeChainErrorFn(job):
    """Return True if the command exit 1 | wc -l raises a ContainerError."""
    parameters = [ ['exit', '1'], ['wc', '-l'] ]
    try:
        apiDockerCall(job,
                      image='quay.io/ucsc_cgl/spooky_test',
                      parameters=parameters)
    except ContainerError:
        return True
    return False 
开发者ID:DataBiosphere,项目名称:toil,代码行数:12,代码来源:dockerTest.py

示例6: execute_command

# 需要导入模块: from docker import errors [as 别名]
# 或者: from docker.errors import ContainerError [as 别名]
def execute_command(self, command, stdin=None, json_output=True, **kwargs):

        command = ['--output=json'] + command

        full_command = ' '.join([shlex.quote(el) for el in command])

        if stdin:
            full_command = '-c "echo -n \\"{}\\" | subkey {}"'.format(stdin, full_command)
        else:
            full_command = '-c "subkey {}"'.format(full_command)

        client = docker.from_env()
        try:
            output = client.containers.run(self.docker_image, full_command, entrypoint='/bin/sh')

            output = output[0:-1].decode()

            if json_output:
                output = json.loads(output)

            return output

        except ContainerError as e:
            raise CommandFailException('Docker Error: ', e)

        except json.JSONDecodeError as e:
            raise CommandFailException('Invalid format: ', e) 
开发者ID:polkascan,项目名称:py-substrate-interface,代码行数:29,代码来源:subkey.py

示例7: _docker_build

# 需要导入模块: from docker import errors [as 别名]
# 或者: from docker.errors import ContainerError [as 别名]
def _docker_build(cls, external_path):
        internal_path = PurePosixPath("/project")
        command = " ".join(cls._make_pip_command(internal_path))
        LOG.debug("command is '%s'", command)

        volumes = {str(external_path): {"bind": str(internal_path), "mode": "rw"}}
        image = f"lambci/lambda:build-{cls.RUNTIME}"
        LOG.warning(
            "Starting Docker build. This may take several minutes if the "
            "image '%s' needs to be pulled first.",
            image,
        )
        docker_client = docker.from_env()
        try:
            logs = docker_client.containers.run(
                image=image,
                command=command,
                auto_remove=True,
                volumes=volumes,
                stream=True,
                user=f"{os.geteuid()}:{os.getgid()}",
            )
        except RequestsConnectionError as e:
            # it seems quite hard to reliably extract the cause from
            # ConnectionError. we replace it with a friendlier error message
            # and preserve the cause for debug traceback
            cause = RequestsConnectionError(
                "Could not connect to docker - is it running?"
            )
            cause.__cause__ = e
            raise DownstreamError("Error running docker build") from cause
        except (ContainerError, ImageLoadError, APIError) as e:
            raise DownstreamError("Error running docker build") from e
        LOG.debug("Build running. Output:")
        for line in logs:
            LOG.debug(line.rstrip(b"\n").decode("utf-8")) 
开发者ID:aws-cloudformation,项目名称:cloudformation-cli-python-plugin,代码行数:38,代码来源:codegen.py


注:本文中的docker.errors.ContainerError方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。