這是我使用 .NET 6 和 ASP.NET Core 創建的一個非常簡單的 API,我正在嘗試對其進行 docker 化。
運行 docker build 命令時,我總是遇到同樣的錯誤。這是我的碼頭檔案:
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build-env
WORKDIR /app
# Copy csproj and restore as distinct layers
COPY *.csproj ./
RUN dotnet restore "MyAPI/MyAPI.csproj" //this is where the build stops
# Copy everything else and build
COPY .. ./
RUN dotnet publish -c Release -o out
# Build runtime image
FROM mcr.microsoft.com/dotnet/aspnet:6.0
WORKDIR /app
EXPOSE 80
COPY --from=build-env /app/out .
ENTRYPOINT ["dotnet", "MyAPI.dll"]
這是我得到的錯誤:
=> ERROR [build-env 4/6] RUN dotnet restore 0.7s
------
> [build-env 4/6] RUN dotnet restore:
#11 0.676 MSBUILD : error MSB1003: Specify a project or solution file. The current working directory does not contain a project or solution file.
------
executor failed running [/bin/sh -c dotnet restore]: exit code: 1
我想問題是路徑問題,我已經嘗試過將路徑傳遞到我的檔案夾的方法,但它一直給我同樣的錯誤。
如果我嘗試dotnet restore在終端中單獨運行該命令,它會告訴我路徑是正確的。
可能是什么問題呢?
uj5u.com熱心網友回復:
COPY *.csproj ./找不到任何要復制的內容,因為您的 .csproj 檔案位于 MyAPI/ 目錄中。
將陳述句更改為
COPY MyAPI/MyAPI.csproj MyAPI/
您復制其余檔案并發布專案的位置也應更改為
COPY . ./
RUN dotnet publish -c Release -o out MyAPI/MyAPI.csproj
uj5u.com熱心網友回復:
請檢查csproj檔案是否真的存在于您PC檔案系統的路徑上yourSolutionRootFolder/MyAPI/MyAPI.csproj
您可能在路徑中有錯字?大寫/小寫錯字?
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/480092.html
標籤:码头工人 asp.net 核心 dockerfile .net-6.0
