def _build_image(self, base_image, docker_tag, layers):
dockerfile_content = self._generate_dockerfile(base_image, layers)<EOL>dockerfile_name = "<STR_LIT>" + str(uuid.uuid4())<EOL>full_dockerfile_path = Path(self.layer_downloader.layer_cache, dockerfile_name)<EOL>try:<EOL><INDENT>with open(str(full_dockerfile_path), "<STR_LIT:w>") as dockerfile:<EOL><INDENT>dockerfile.write(dockerfile_content)<EOL><DEDENT>tar_paths = {str(full_dockerfile_path): "<STR_LIT>"}<EOL>for layer in layers:<EOL><INDENT>tar_paths[layer.codeuri] = '<STR_LIT:/>' + layer.name<EOL><DEDENT>with create_tarball(tar_paths) as tarballfile:<EOL><INDENT>try:<EOL><INDENT>self.docker_client.images.build(fileobj=tarballfile,<EOL>custom_context=True,<EOL>rm=True,<EOL>tag=docker_tag,<EOL>pull=not self.skip_pull_image)<EOL><DEDENT>except (docker.errors.BuildError, docker.errors.APIError):<EOL><INDENT>LOG.exception("<STR_LIT>")<EOL>raise ImageBuildException("<STR_LIT>")<EOL><DEDENT><DEDENT><DEDENT>finally:<EOL><INDENT>if full_dockerfile_path.exists():<EOL><INDENT>full_dockerfile_path.unlink()<EOL><DEDENT><DEDENT>
Builds the image

Parameters
----------
base_image str
    Base Image to use for the new image
docker_tag
    Docker tag (REPOSITORY:TAG) to use when building the image
layers list(samcli.commands.local.lib.provider.Layer)
    List of Layers to be use to mount in the image

Returns
-------
None

Raises
------
samcli.commands.local.cli_common.user_exceptions.ImageBuildException
    When docker fails to build the image