C#C
C#11mo ago
Maskoe

Access files in a docker image

I am completely defeated.
All im trying to do is access a file with type = content and output = preserver newest in docker

this is my dockerfile
FROM mcr.microsoft.com/dotnet/aspnet:9.0 AS base
WORKDIR /app
EXPOSE 5050
ENV ASPNETCORE_URLS=http://+:5050

FROM mcr.microsoft.com/dotnet/sdk:9.0 AS build
ARG BUILD_CONFIGURATION=Release
WORKDIR /src
COPY ["MediaLib.Jobs/appsettings*.json", "MediaLib.Jobs/"]
COPY . .
WORKDIR "/src/MediaLib.Jobs"
RUN dotnet build "MediaLib.Jobs.csproj" -c $BUILD_CONFIGURATION -o /app/build

FROM build AS publish
ARG BUILD_CONFIGURATION=Release
RUN dotnet publish "MediaLib.Jobs.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
COPY --from=build /app/build .
RUN ls -R /app/Infra/EmailTemplates  
ENTRYPOINT ["dotnet", "MediaLib.Jobs.dll"]


I tried all kinds of different combinations and debug logs for about 10 hours
var currentDirectory = AppDomain.CurrentDomain.BaseDirectory;
            var templatePath = Path.Combine(currentDirectory, "Infra", "EmailTemplates", "PasswordResetEmail.cshtml");

I cant find any combination that works. I just want to access this file. I can see its in the docker image.
With the debug logs im getting the correct path, its just not there if I do File.Exists. If I check locally or in prod within the terminal of the image, its there.

this is in my csproj
        <Content Update="Infra\EmailTemplates\PasswordResetEmail.cshtml">
            <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
        </Content>
Was this page helpful?