使用 Docker 运行 .Net Core API (v2.2) 时,无法找到 .XML 文件以进行 swagger 并尝试在本地主机上访问它时崩溃,并出现以下错误:
FileNotFoundException: Could not find file '/app/Account.API.XML'.
在检查容器时,我可以看到该文件存在于目录中,但我不确定为什么它无法检测到它。这是我的容器的内容:
root@538b7c4e4b45:/app# ls
Account.API.deps.json Account.API.pdb Account.API.xml Swashbuckle.AspNetCore.Swagger.dll Swashbuckle.AspNetCore.SwaggerUI.dll appsettings.Development.json web.config Account.API.dll Account.API.runtimeconfig.json Microsoft.OpenApi.dll Swashbuckle.AspNetCore.SwaggerGen.dll Swashbuckle.AspNetCore.dll appsettings.json
Run Code Online (Sandbox Code Playgroud)
这是我的 Dockerfile 的内容:
# Create a release executable of the service
FROM microsoft/dotnet:2.2-sdk AS builder
WORKDIR /build
COPY ./ ./
RUN dotnet publish Account.API/Account.API.csproj --framework netcoreapp2.2 --configuration Release --output /release
# Run the executable with .Net Core runtime
FROM microsoft/dotnet:2.2-aspnetcore-runtime
ARG ENV_NAME
ENV ASPNETCORE_ENVIRONMENT=$ENV_NAME
WORKDIR /app …Run Code Online (Sandbox Code Playgroud)