我有一个 .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 映像也将在那里