def build_image(self, dockerfile_path: str, image_name: str, context_path: str = None): cmd = self._docker_cmd() dockerfile_path = Util.resolve_dockerfile_path(dockerfile_path) context_path = context_path or os.path.dirname(dockerfile_path) cmd += ["build", "-t", image_name, "-f", dockerfile_path, context_path] LOG.debug("Building Docker image: %s", cmd) try: run(cmd) except subprocess.CalledProcessError as e: raise ContainerException( f"Docker build process returned with error code {e.returncode}", e.stdout, e.stderr ) from e
def build_image(self, dockerfile_path: str, image_name: str, context_path: str = None): try: dockerfile_path = Util.resolve_dockerfile_path(dockerfile_path) context_path = context_path or os.path.dirname(dockerfile_path) LOG.debug("Building Docker image %s from %s", image_name, dockerfile_path) self.client().images.build( path=context_path, dockerfile=dockerfile_path, tag=image_name, rm=True, ) except APIError as e: raise ContainerException("Unable to build Docker image") from e