title: .NET Core on Docker: Access to the path is denied
body: <p>I have a .Net core web application, which is hosted on a CentOS machine.
  Everything works fine, except when I call a function which needs a specific file on the server (it combines several images and generates a PDF), I get the following error:</p>
  <blockquote>
  <p>System.UnauthorizedAccessException: Access to the path '[path]' is
  denied.</p>
  </blockquote>
  <p>The project is built using the Visual Studio auto-generated dockerfile, and docker-compose file.</p>
  <p>Here are the contents:</p>
  <p>Dockerfile</p>
  <pre><code>FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-buster-slim AS base
  WORKDIR /app
  EXPOSE 80
  
  FROM mcr.microsoft.com/dotnet/core/sdk:3.1-buster AS build
  WORKDIR /src
  COPY [&quot;lifeandme-v2/lifeandme-v2.csproj&quot;, &quot;lifeandme-v2/&quot;]
  RUN dotnet restore &quot;lifeandme-v2/lifeandme-v2.csproj&quot;
  COPY . .
  WORKDIR &quot;/src/lifeandme-v2&quot;
  RUN dotnet build &quot;lifeandme-v2.csproj&quot; -c Release -o /app/build
  
  FROM build AS publish
  RUN dotnet publish &quot;lifeandme-v2.csproj&quot; -c Release -o /app/publish
  
  FROM base AS final
  WORKDIR /app
  COPY --from=publish /app/publish .
  COPY . /app/publish
  ENTRYPOINT [&quot;dotnet&quot;, &quot;lifeandme-v2.dll&quot;]
  </code></pre>
  <p>The files which the application tries to access during runtime, are located in my project root subdirectories, hence I've added the penultimate line in order to copy the entire contents of the root of my project to the final container.</p>
  <p>I have also tried entering the container as it is running, and changing the chmod of the entire /app folder to 777, but still I get the same error. And I have tried adding this to my dockerfile, just before the final line:</p>
  <pre><code>RUN chmod -R 777 /app
  </code></pre>
  <p>Again, the same error.</p>