我正在嘗試在本地主機的 Docker 上運行我的第一個 .Net Core Web API(Core 2.2)。我在創建專案時啟用了 Docker 支持(Linux)。
Docker 檔案
FROM microsoft/dotnet:2.2-aspnetcore-runtime AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443
FROM microsoft/dotnet:2.2-sdk AS build
WORKDIR /src
COPY ["SampleApp/SampleApp.csproj", "SampleApp/"]
RUN dotnet restore "SampleApp/SampleApp.csproj"
COPY . .
WORKDIR "/src/SampleApp"
RUN dotnet build "SampleApp.csproj" -c Release -o /app
FROM build AS publish
RUN dotnet publish "SampleApp.csproj" -c Release -o /app
FROM base AS final
WORKDIR /app
COPY --from=publish /app .
ENTRYPOINT ["dotnet", "SampleApp.dll"]
當我嘗試從 VS 在 Docker 上運行 API 時,出現以下錯誤
Error CTP1001 An error occurred while attempting to build Docker image.
當我查看輸出視窗時
1>------ Build started: Project: SampleApp, Configuration: Debug Any CPU ------
1>SampleApp -> E:\Sandbox\ContainerDeployment\SampleApp\SampleApp\bin\Debug\netcoreapp2.2\SampleApp.dll
1>docker build -f "E:\Sandbox\ContainerDeployment\SampleApp\SampleApp\Dockerfile" -t sampleapp:dev --target base --label "com.microsoft.created-by=visual-studio" "E:\Sandbox\ContainerDeployment\SampleApp"
1>#1 [internal] load build definition from Dockerfile
1>#1 transferring dockerfile: 32B done
1>#2 [internal] load .dockerignore
1>#2 sha256:0237a52bf01ebc117c468d73e0fc890d42166c17898aa5c4fd0fd96dcaee67e8
1>#1 sha256:bb73acd705ce58a2a5ccfdd8d06dc6e46e04a03a430562efdf99961870d2e178
1>#2 transferring context: 34B done
1>
1>#2 DONE 0.0s
1>
1>#3 sha256:2209054a124f7bc1424fa6735d588f36916bcec272f45a5e3e54f7288e65d73e
1>#3 [internal] load metadata for docker.io/microsoft/dotnet:2.2-aspnetcore-runtime
1>#1 DONE 0.0s
1>#3 ERROR: pull access denied, repository does not exist or may require authorization: server message: insufficient_scope: authorization failed
1>------
1>------
1> > [internal] load metadata for docker.io/microsoft/dotnet:2.2-aspnetcore-runtime:
1>failed to solve with frontend dockerfile.v0: failed to create LLB definition: pull access denied, repository does not exist or may require authorization: server message: insufficient_scope: authorization failed
1>C:\Users\gopalk\.nuget\packages\microsoft.visualstudio.azure.containers.tools.targets\1.4.10\build\Container.targets(258,5): error CTP1001: An error occurred while attempting to build Docker image.
1>Done building project "SampleApp.csproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
uj5u.com熱心網友回復:
不再支持 .NET Core 2.2 版,當前的 LTS .NET 版本是 6.0。您可以在docker hub上查看 ASP.NET Core 運行時的現有映像版本。
在您的機器上更新 .NET 版本:
如果您使用的是 Visual Studio,則可以使用 Visual Studio 安裝程式來安裝 .NET 6 及其附帶的所有模板。然后,您應該使用 .NET 版本 6 重新創建您的專案,或者將現有專案升級到 .NET 6,然后重新生成您的 dockerfile,您可以通過右鍵單擊專案檔案 --> 添加 -- 在 Visual Studio 中生成一個 Dockerfile > docker 支持,在執行這些步驟之前,您應該洗掉現有的 dockerfile。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/389753.html
