我有一個 .net 6 web api。
當用戶上傳影像時,它應該存盤在 wwwroot 檔案夾中。
當我運行 docker 時,我從后端收到此錯誤:
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
這是我的 Docker 檔案:
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"]
如何創建 wwwRoot 卷并存盤用戶在運行時上傳的影像?
- 該卷將在 Heroku 中,因為 docker 影像也將在那里
uj5u.com熱心網友回復:
檔案系統在 Heroku 中是短暫的。上傳到磁盤只是暫時的。您應該上傳到云存盤系統(azure blob、AWS S3 等)并將 URL 保存在資料庫中的某個位置。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/393739.html
