I'm using a containerized ASP.Net Core (5) Web Api app. The container is (Linux based container) running Debian Stretch. Everything is working fine except that the static files in app/wwwroot of the container don't get rendered when it supposed to be. I even made sure that the imgs, css, fonts files are actually there in the container at "app/wwwroot" and they exist!
also the in Program.cs/CreateHostBuilder(): this line is there
.UseContentRoot(Directory.GetCurrentDirectory())
also, in Startup.cs I did this:
app.UseStaticFiles();
So, I don't know what could be the problem ? is it related to Rotativa / wkhtmltopdf library, since its generated PDF file should use these static files? or is it related to the Dockerfile itself? this is the Dockerfile:
FROM mcr.microsoft.com/dotnet/aspnet:5.0 AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443
FROM mcr.microsoft.com/dotnet/sdk:5.0 AS build
WORKDIR /src
COPY ["src/Api/Api.csproj", "src/Api/"]
COPY ["src/Application/Application.csproj", "src/Application/"]
COPY ["src/Domain/Domain.csproj", "src/Domain/"]
COPY ["src/Infrastructure.Shared/Infrastructure.Shared.csproj", "src/Infrastructure.Shared/"]
COPY ["src/Persistence/Persistence.csproj", "src/Persistence/"]
COPY ["src/Api/wwwroot", "src/Api/"]
COPY ["src/Api/wwwroot", "./"]
COPY ["src/Api", "src/"]
COPY . ./
RUN dotnet restore "src/Api/Api.csproj"
RUN dotnet restore "src/Api"
COPY . .
WORKDIR "/src/src/Api"
RUN dotnet build "Api.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "Api.csproj" -c Release -o /app/publish
RUN dotnet publish "/src/src/Api" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
VOLUME /app/wwwroot
RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y locales libgdiplus wkhtmltopdf
RUN ln -s /usr/bin/wkhtmltopdf /app/wwwroot/Rotativa/wkhtmltopdf
ENTRYPOINT ["dotnet", "Api.dll"]
CodePudding user response:
You might need to set the properties of static files to always copy try this
- in visual studio right-click on your file.
- Click on the Properties.
- Set Copy to output directory to Copy always.
See attached screenshot
CodePudding user response:
the issue wasn't because of path as I thought, it was because the container ip address, thank you everyone

