C
C#3mo 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"]
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");
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>
<Content Update="Infra\EmailTemplates\PasswordResetEmail.cshtml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
3 Replies
Keswiik
Keswiik3mo ago
What path is the template file located at in your docker container? And what path is generated by var templatePath = Path.Combine(currentDirectory, "Infra", "EmailTemplates", "PasswordResetEmail.cshtml");?
Unknown User
Unknown User3mo ago
Message Not Public
Sign In & Join Server To View
Maskoe
MaskoeOP3mo ago
im using it with fluentemail, so its not in my actual code that path returns "/app/Infra..." which is where it is in the image i made it work with embeddedResource, but it feels like giving up

Did you find this page helpful?