Static Files in wwwroot not contained in Docker Image Static Files in wwwroot not contained in Docker Image kubernetes kubernetes

Static Files in wwwroot not contained in Docker Image


Okay, now I found out myself.

The error was in the Dockerfile itself.I needed to explicitly say, which csproj file to build and which one to publish. This is what I learned here.

Actually, no need to define something like "include this file, and this directory" in the csproj file.

And it is actually important to say, that the wwwroot directory is NOT compiled into the dll. It exists inside the /app folder in the container (that info I couldn't find anywhere, but I got a hint here).

This also gives the ability to map an external folder to the container (so you can edit the static files without having to re-dockerize it over and over again - of course this is not meant for production environments).

Also important to say is, that for production environments and generally for all static files you don't want to come into the image (like source SCSS, un-obfuscated JS, temporary files, copies of backups of copies of a file, and so on), a .dockerignore file should be used.

If you do not, the static files may be accessible directly via the browser, because they come directly into the wwwroot directory.

So here is my working Dockerfile.

FROM mcr.microsoft.com/dotnet/core/aspnet:3.0-buster-slim AS baseWORKDIR /appEXPOSE 80EXPOSE 443FROM mcr.microsoft.com/dotnet/core/sdk:3.0-buster AS buildWORKDIR /srcCOPY all.sln ./    # not sure if I need thisCOPY one/one.csproj one/COPY two/two.csproj two/COPY three/three.csproj three/COPY . ./RUN dotnet build "/src/one/one.csproj" -c Release -o /appRUN dotnet build "/src/two/two.csproj" -c Release -o /appRUN dotnet build "/src/three/three.csproj" -c Release -o /appFROM build AS publishRUN dotnet publish "/src/one/one.csproj" -c Release -o /appFROM base AS finalWORKDIR /appCOPY --from=publish /app .ENTRYPOINT ["dotnet", "one.dll"]

Hope my explanations help others with this problem in future.

Thank you! xola