本文章仅做记录异常用途
使用.net core右键LY.ProductSchedularService.Api自动生成dockerfile
并使用
docker build -t my_service .
构建镜像时,报错提示:
failed to compute cache key: “/App/LY/NetCore/LY.Common/LY.Common.csproj” not found: not found
DockerFile如下
#See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging.
#Depending on the operating system of the host machines(s) that will build or run the containers, the image specified in the FROM statement may need to be changed.
#For more information, please see https://aka.ms/containercompat
FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base
WORKDIR /app
EXPOSE 5677
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
WORKDIR /src
COPY ["App/LY/NetCore/LY.ProductSchedularService.Api/LY.ProductSchedularService.Api.csproj", "App/LY/NetCore/LY.ProductSchedularService.Api/"]
COPY ["App/LY/NetCore/LY.Entity/LY.Entity.csproj", "App/LY/NetCore/LY.Entity/"]
COPY ["App/LY/NetCore/LY.Common/LY.Common.csproj", "App/LY/NetCore/LY.Common/"]
RUN dotnet restore "App/LY/NetCore/LY.ProductSchedularService.Api/LY.ProductSchedularService.Api.csproj"
COPY . .
WORKDIR "/src/App/LY/NetCore/LY.ProductSchedularService.Api"
RUN dotnet build "LY.ProductSchedularService.Api.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "LY.ProductSchedularService.Api.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "LY.ProductSchedularService.Api.dll"]
原因分析:
Dockerfile不能跟LY.ProductSchedularService.Api项目同级的,因为该项目依赖引用了其他的2个项目,使用这个docker build命令会提示找不到另外的项目
解决方法:
把Dockerfile放于与App文件夹同级的目录下即可