def _docker_build(cls, external_path): cls._check_for_support_lib_sdist(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"))