我正在嘗試在我的應用程式.Net 6.0中執行“ docker build ” ,但在 Dockerfile 中的 Dotnet restore 中收到錯誤訊息。應用程式在本地正常執行,沒有任何錯誤。
碼頭工人命令:
docker build -t aspnetcore-docker-image .
終端錯誤:
=> ERROR [build 7/9] RUN dotnet restore ./DevFreela.API/DevFreela.API.csproj 0.2s
------
> [build 7/9] RUN dotnet restore ./DevFreela.API/DevFreela.API.csproj:
#11 0.185 Could not execute because the application was not found or a compatible .NET SDK is not installed.
#11 0.185 Possible reasons for this include:
#11 0.185 * You intended to execute a .NET program:
#11 0.185 The application 'restore' does not exist.
#11 0.185 * You intended to execute a .NET SDK command:
#11 0.185 It was not possible to find any installed .NET SDKs.
#11 0.185 Install a .NET SDK from:
#11 0.185 https://aka.ms/dotnet-download
------
executor failed running [/bin/sh -c dotnet restore ./DevFreela.API/DevFreela.API.csproj]: exit code: 145
我的 Dockerfile
# .NET Core SDK
FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS build
# Sets the working directory
WORKDIR /app
# Copy Projects
#COPY *.sln .
COPY Src/DevFreela.API/DevFreela.API.csproj ./DevFreela.API/
COPY Src/DevFreela.Application/DevFreela.Application.csproj ./DevFreela.Application/
COPY Src/DevFreela.Core/DevFreela.Core.csproj ./DevFreela.Core/
COPY Src/DevFreela.Infrastructure/DevFreela.Infrastructure.csproj ./DevFreela.Infrastructure/
# .NET Core Restore
RUN dotnet restore ./DevFreela.API/DevFreela.API.csproj
# Copy All Files
COPY Src ./
# .NET Core Build and Publish
RUN dotnet publish ./DevFreela.Api/DevFreela.Api.csproj -c Release -o /publish
# ASP.NET Core Runtime
FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS runtime
WORKDIR /app
COPY --from=build /publish ./
EXPOSE 80 5195 7066
ENV ASPNETCORE_URLS=http:// :5195;https:// :7066
ENTRYPOINT ["dotnet", "DevFreela.API.dll"]
專案結構:

完整的終端日志:
=> [internal] load build definition from Dockerfile 0.0s
=> => transferring dockerfile: 938B 0.0s
=> [internal] load .dockerignore 0.0s
=> => transferring context: 35B 0.0s
=> [internal] load metadata for mcr.microsoft.com/dotnet/aspnet:6.0 0.6s
=> [internal] load build context 0.0s
=> => transferring context: 13.14kB 0.0s
=> [runtime 1/3] FROM mcr.microsoft.com/dotnet/aspnet:6.0@sha256:26ef9dc4aa354cc4aa4ae533c97f92d0d72c5e848f6968660be51d9 0.0s
=> CACHED [runtime 2/3] WORKDIR /app 0.0s
=> CACHED [build 3/9] COPY Src/DevFreela.API/DevFreela.API.csproj ./DevFreela.API/ 0.0s
=> CACHED [build 4/9] COPY Src/DevFreela.Application/DevFreela.Application.csproj ./DevFreela.Application/ 0.0s
=> CACHED [build 5/9] COPY Src/DevFreela.Core/DevFreela.Core.csproj ./DevFreela.Core/ 0.0s
=> CACHED [build 6/9] COPY Src/DevFreela.Infrastructure/DevFreela.Infrastructure.csproj ./DevFreela.Infrastructure/ 0.0s
=> ERROR [build 7/9] RUN dotnet restore ./DevFreela.API/DevFreela.API.csproj 0.2s
------
> [build 7/9] RUN dotnet restore ./DevFreela.API/DevFreela.API.csproj:
#11 0.185 Could not execute because the application was not found or a compatible .NET SDK is not installed.
#11 0.185 Possible reasons for this include:
#11 0.185 * You intended to execute a .NET program:
#11 0.185 The application 'restore' does not exist.
#11 0.185 * You intended to execute a .NET SDK command:
#11 0.185 It was not possible to find any installed .NET SDKs.
#11 0.185 Install a .NET SDK from:
#11 0.185 https://aka.ms/dotnet-download
------
executor failed running [/bin/sh -c dotnet restore ./DevFreela.API/DevFreela.API.csproj]: exit code: 145
uj5u.com熱心網友回復:
您正在使用aspnet不包含 SDK 的影像,因此您無法使用它進行構建。您需要sdk像這樣的 Dockerfile 的第一部分的影像
# .NET Core SDK
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
# Sets the working directory
WORKDIR /app
# Copy Projects
#COPY *.sln .
COPY Src/DevFreela.API/DevFreela.API.csproj ./DevFreela.API/
COPY Src/DevFreela.Application/DevFreela.Application.csproj ./DevFreela.Application/
COPY Src/DevFreela.Core/DevFreela.Core.csproj ./DevFreela.Core/
COPY Src/DevFreela.Infrastructure/DevFreela.Infrastructure.csproj ./DevFreela.Infrastructure/
# .NET Core Restore
RUN dotnet restore ./DevFreela.API/DevFreela.API.csproj
# Copy All Files
COPY Src ./
# .NET Core Build and Publish
RUN dotnet publish ./DevFreela.Api/DevFreela.Api.csproj -c Release -o /publish
# ASP.NET Core Runtime
FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS runtime
WORKDIR /app
COPY --from=build /publish ./
EXPOSE 80 5195 7066
ENV ASPNETCORE_URLS=http:// :5195;https:// :7066
ENTRYPOINT ["dotnet", "DevFreela.API.dll"]
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/457916.html
