在 docker 容器上写入文件时出现权限被拒绝错误

Permission denied error when writing file on docker container

我在尝试将 pdf 文件流式传输到浏览器时遇到权限被拒绝的问题。我已经在 DockerFile 中设置了对临时文件夹的读取、写入和执行权限。关于我做错了什么的任何指示? 我将 ASP.Net 核心应用程序托管为 Azure 应用程序服务和 docker Linux 容器(如果有的话)。

堆栈跟踪:

Exception occured: Syncfusion.Pdf.PdfException: /usr/bin/xvfb-run: 183: /usr/bin/xvfb-run: /app/QtBinariesLinux/Syncfusion.WebKitWrapper: Permission denied    
   at Syncfusion.HtmlConverter.HtmlConverter.ConvertHtmlToPdf(String url, Int32 width, Int32 height)

Dockerfile:

FROM mcr.microsoft.com/dotnet/core/aspnet:2.2-stretch-slim AS base
RUN chmod a+rwx -R /usr/bin/xvfb-run
WORKDIR /app
EXPOSE 80
EXPOSE 443

FROM mcr.microsoft.com/dotnet/core/sdk:2.2-stretch AS build
WORKDIR /src
COPY ["Scrubber/Scrubber.csproj", "Scrubber/"]
COPY ["SimplerProducts.MicrosoftEntityFrameworkCoreStorage/SimplerProducts.MicrosoftEntityFrameworkCoreStorage.csproj", "SimplerProducts.MicrosoftEntityFrameworkCoreStorage/"]
RUN dotnet restore "Scrubber/Scrubber.csproj"
COPY . .
WORKDIR "/src/Scrubber"
RUN dotnet build "Scrubber.csproj" -c Release -o /app

FROM build AS publish
RUN dotnet publish "Scrubber.csproj" -c Release -o /app

FROM base AS final
WORKDIR /app
COPY --from=publish /app .
ENTRYPOINT ["dotnet", "Scrubber.dll"]

CSharp代码:

public IActionResult OnPostExportToPDFAsync()
    {
      var htmlToPdfConverter = new HtmlToPdfConverter
      {
        ConverterSettings = new WebKitConverterSettings
        {
          WebKitPath = Path.Combine(HostingEnvironment.ContentRootPath, "QtBinariesLinux"),
          TempPath = Path.GetTempPath(),
          SplitTextLines = false,
          SplitImages = false,
          EnableRepeatTableHeader = true,
          EnableRepeatTableFooter = true,
    }
      };
      var pdfDocument = htmlToPdfConverter.Convert("http://www.google.com");
      var memoryStream = new MemoryStream();
      pdfDocument.Save(memoryStream);
      return File(memoryStream.ToArray(), System.Net.Mime.MediaTypeNames.Application.Pdf, "Sample.pdf");
    }

这更像是一个 Azure 问题,而不是 Docker 或文件权限问题。 我能够通过将应用服务的 Azure 资源组从 F1-Free 更改为 S1-Basic 来解决这个问题。

转换器可能会在 Azure 上的 Consumption/Free/Shared 托管计划下引发异常。请确保您没有使用上述托管计划在 Azure 环境中发布。由于这些托管计划的访问限制和限制,它阻止了浏览器进程的加载。因此,转换将在 Azure 环境的 Consumption/Free/Shared 托管计划中失败。其他主机方案没有加载浏览器进程的限制。