.NET Core on Docker: Access to the path is denied

Viewed 4027

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:

System.UnauthorizedAccessException: Access to the path '[path]' is denied.

The project is built using the Visual Studio auto-generated dockerfile, and docker-compose file.

Here are the contents:

Dockerfile

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 ["lifeandme-v2/lifeandme-v2.csproj", "lifeandme-v2/"]
RUN dotnet restore "lifeandme-v2/lifeandme-v2.csproj"
COPY . .
WORKDIR "/src/lifeandme-v2"
RUN dotnet build "lifeandme-v2.csproj" -c Release -o /app/build

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

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

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.

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:

RUN chmod -R 777 /app

Again, the same error.

0 Answers
Related