I have a .net 6 web api.
When a user upload an image it should store in wwwroot folder.
when i run docker i have this error from the backend:
backend | Unhandled exception. System.IO.DirectoryNotFoundException: /wwwroot\images/
backend | at Microsoft.Extensions.FileProviders.PhysicalFileProvider..ctor(String root, ExclusionFilters filters)
backend | at Microsoft.Extensions.FileProviders.PhysicalFileProvider..ctor(String root)
backend | at Program.<Main>$(String[] args) in /RealEstateAPI/Program.cs:line 65
backend exited with code 139
This is my Docker file:
FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base
WORKDIR /
EXPOSE 80
EXPOSE 443
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
WORKDIR /
COPY RealEstateAPI/appsettings.json ./RealEstateAPI/AppSettings.json
COPY RealEstateAPI/appsettings.Development.json ./RealEstateAPI/AppSettings.Development.json
COPY RealEstateAPI/wwwroot ./RealEstateAPI/
COPY . .
RUN dotnet restore "RealEstateAPI/RealEstateAPI.csproj"
COPY . .
WORKDIR "/RealEstateAPI"
RUN dotnet build "RealEstateAPI.csproj" -c Release -o /build
FROM build AS publish
RUN dotnet publish "RealEstateAPI.csproj" -c Release -o /publish
FROM base AS final
WORKDIR /
COPY --from=publish /publish .
ENTRYPOINT ["dotnet", "RealEstateAPI.dll"]
How can i create a wwwRoot volume and store there images that users are uploading at run time?
The filesystems are ephemeral in Heroku. Uploads to disk will only be temporary. You should upload to a cloud storage system (azure blobs, AWS S3, etc) and save the URLs in a database somewhere.