Visual studio docker build no such file or directory
作者:互联网
在我构建新的镜像的时候, 发生 了 no such file or directory 的错误。 这个错误找了半天, 没头绪,项目结构是这样的:
WebApplication1 建立在根目录下,是可以release构建成功的,而WebApplication2是建立在根目录下的src目录下面的,release 构建执行到step8的时候就抛出no such file or directory 错误了,
dockerfile 文件如下:
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"]
项目结构如下:
仔细排查得知,原来是dockerfile 的workdir设定问题,最终结果如下:
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"]
标签:WebApplication3,WebApplication2,WORKDIR,no,csproj,app,Visual,studio,dotnet 来源: https://www.cnblogs.com/shatanku/p/10827291.html