简体   繁体   中英

Permission denied error when writing file on docker container

I am getting a permission denied when trying to stream a pdf file to the browser. I have set the read, write and execute permissions for the temp folder in the DockerFile. Any pointers on what I be doing wrong? I am hosting the ASP.Net Core application as a Azure App service and docker Linux container, if that matters.

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 code:

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

This was more of a Azure issue rather than a Docker or file permissions issue. I was able to fix the issue by changing the Azure resource group from F1-Free to S1-Basic, for the App Service.

The converter may throws the exception under Consumption/Free/Shared hosting plans on Azure. Please make sure you are not using the mentioned hosting plans to publish on Azure environment. Due to the access restrictions and limitation of these hosting plan, it prevents the loading of the browser process. So, the conversion will be failed in the Consumption/Free/Shared hosting plans on Azure environment. Other hosting plans does not have the restriction for loading the browser process.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM