Microsoft FileProviders Error (File does exist) [Docker]

Viewed 51

I am currently trying to dockerize my project and I am getting a really strange error that I can't seem to fix. This error prevents me from using docker run and it doesn't change no matter what. I have tried to delete any and all code related to pathing for files and still nothing changes which makes no sense to me. Below are all my files and the relevant code.

P.S This error never popped up during runtime or during build, only after creating the first docker image and trying to run it.

Command:

C:\Users\Jonathan\Downloads\College_DB\WebAPI\WebAPI [main ↓1 +1 ~10 -0 !]> docker run -p 5000:5000 webapi

Error:

Unhandled exception. System.IO.DirectoryNotFoundException: /app/Photos/
   at Microsoft.Extensions.FileProviders.PhysicalFileProvider..ctor(String root, ExclusionFilters filters)
   at Microsoft.Extensions.FileProviders.PhysicalFileProvider..ctor(String root)
   at Program.<Main>$(String[] args) in /src/Program.cs:line 30

Program.cs:

using Microsoft.Extensions.FileProviders;
using Newtonsoft.Json.Serialization;

...

// Use files (photo files)
app.UseStaticFiles(new StaticFileOptions
{
    FileProvider = new PhysicalFileProvider(
            Path.Combine(Directory.GetCurrentDirectory(), "Photos")),
    RequestPath = "/Photos"
});

ONLY other mention of pathing to /Photos: ProfessorController.cs:

var physicalPath = _env.ContentRootPath + "/Photos/" + filename;

                using (var stream = new FileStream(physicalPath, FileMode.Create))
                {
                    postedFile.CopyTo(stream);
                }

Dockerfile:

FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
WORKDIR /src

COPY WebAPI.csproj .
RUN dotnet restore "WebAPI.csproj"

COPY . .
RUN dotnet publish "WebAPI.csproj" -c Release -o /publish

FROM build AS final
WORKDIR /app
COPY --from=build /publish .
EXPOSE 5000
ENTRYPOINT ["dotnet", "WebAPI.dll"]

Files Imgur: https://imgur.com/a/BWxcQgV

EDIT: Added Dockerfile

1 Answers
COPY . .  => COPY . ./
WORKDIR /src => WORKDIR /app

This seems to have fixed the issue for me

Related