Visual studio docker build no such file or directory

在我構建新的鏡像的時候, 發生 了  no such file or directory 的錯誤。  這個錯誤找了半天, 沒頭緒,項目結構是這樣的:docker

WebApplication1 創建在根目錄下,是能夠release構建成功的,而WebApplication2是創建在根目錄下的src目錄下面的,release 構建執行到step8的時候就拋出no such file or directory 錯誤了,app

dockerfile 文件以下:ui

FROM microsoft/dotnet:2.2-aspnetcore-runtime AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443

FROM microsoft/dotnet:2.2-sdk AS build
WORKDIR /WebApplication6/src
COPY ["src/WebApplication2/WebApplication2.csproj", "src/WebApplication2/"]
RUN dotnet restore "src/WebApplication2/WebApplication2.csproj"
COPY . .
WORKDIR "/WebApplication6/src/WebApplication2"
RUN dotnet build "WebApplication2.csproj" -c Release -o /app

FROM build AS publish
RUN dotnet publish "WebApplication2.csproj" -c Release -o /app

FROM base AS final
WORKDIR /app
COPY --from=publish /app .
ENTRYPOINT ["dotnet", "WebApplication2.dll"]

  項目結構以下:spa

仔細排查得知,原來是dockerfile 的workdir設定問題,最終結果以下:rest

FROM microsoft/dotnet:2.2-aspnetcore-runtime AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443

FROM microsoft/dotnet:2.2-sdk AS build
WORKDIR /WebApplication6/src
COPY ["WebApplication3/WebApplication3.csproj", "WebApplication3/"]
RUN dotnet restore "WebApplication3/WebApplication3.csproj"
COPY . .
WORKDIR /WebApplication6/src/WebApplication3/
RUN dotnet build "WebApplication3.csproj" -c Release -o /app

FROM build AS publish
RUN dotnet publish "WebApplication3.csproj" -c Release -o /app

FROM base AS final
WORKDIR /app
COPY --from=publish /app .
ENTRYPOINT ["dotnet", "WebApplication3.dll"]
相關文章
相關標籤/搜索