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

时间:2019-07-04 04:31:04

标签: azure docker dockerfile azure-web-sites syncfusion

尝试将pdf文件流式传输到浏览器时,我的权限被拒绝。我已经在DockerFile中设置了temp文件夹的读取,写入和执行权限。关于我在做什么错的任何指示? 如果这很重要,我会将ASP.Net Core应用程序托管为Azure App服务和docker Linux容器。

StackTrace:

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");
    }

2 个答案:

答案 0 :(得分:0)

这更多是Azure问题,而不是Docker或文件权限问题。 通过将App Service的Azure资源组从F1-Free更改为S1-Basic,我能够解决此问题。

答案 1 :(得分:0)

在Azure上的“消费/免费/共享”托管计划下,转换器可能引发异常。请确保您没有使用提到的托管计划在Azure环境上发布。由于访问限制和这些托管计划的限制,它阻止了浏览器进程的加载。因此,在Azure环境上的“消费/免费/共享”托管计划中,转换将失败。其他托管计划没有加载浏览器进程的限制。