使用泊坞窗“未找到在应用程序依赖清单中指定的程序集”

时间:2019-11-18 08:32:27

标签: docker asp.net-core dockerfile asp.net-core-2.2

我正在尝试使用以下dockerfile来对an angular aspnet core 2.2 webapi进行docker化:

FROM mcr.microsoft.com/dotnet/core/sdk:2.2.105 AS build
WORKDIR /src

# Copy csproj and restore as distinct layers
COPY ["Fightplan_v1/Fightplan_v1.csproj", "Fightplan_v1/"]
COPY ["Fightplan_v1.Autogenerate/Fightplan_v1.Autogenerate.csproj", "Fightplan_v1.Autogenerate/"]
COPY ["Fightplan_v1.Autogenerate.Test/Fightplan_v1.Autogenerate.Test.csproj", "Fightplan_v1.Autogenerate.Test/"]
COPY ["Fightplan_v1.Database/Fightplan_v1.Database.csproj", "Fightplan_v1.Database/"]
COPY ["Fightplan_v1.Helpers/Fightplan_v1.Helpers.csproj", "Fightplan_v1.Helpers/"]
COPY ["Fightplan_v1.Jobs/ConvertImagestoBlob/Fightplan_v1.ConvertImagestoBlob.csproj", "Fightplan_v1.Jobs/ConvertImagestoBlob/"]
COPY ["Fightplan_v1.Models/Fightplan_v1.Models.csproj", "Fightplan_v1.Models/"]
COPY ["Fightplan_v1.Shared/Fightplan_v1.Shared.csproj", "Fightplan_v1.Shared/"]
RUN dotnet restore "Fightplan_v1/Fightplan_v1.csproj"

# Copy everything else and build
COPY . .
WORKDIR "/src/Fightplan_v1"
RUN dotnet build "Fightplan_v1.csproj" -c Release -o /app

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

# Build runtime image
FROM mcr.microsoft.com/dotnet/core/aspnet:2.2 AS runtime
WORKDIR /app
COPY --from=build /app .

EXPOSE 80
ENTRYPOINT ["dotnet", "Fightplan_v1.dll"]

使用的构建命令是:

docker build -f .\fp.dockerfile -t test .

构建正常,但是当我尝试使用以下命令运行时:

docker run -p 5100:80 -it test

我收到以下错误: enter image description here

我尝试过:

  1. 在发布的末尾添加-r linux-x64以定义运行时:RUN dotnet publish "Fightplan_v1.csproj" -c Release -o /app -r linux-x64
  2. <PublishWithAspNetCoreTargetManifest>false</PublishWithAspNetCoreTargetManifest>添加到我的.csproj文件中

不幸的是,以上修复程序均无法正常工作。

由于这是一个有角度的应用程序和一个webapi的组合项目,我可能会缺少一些安装/依赖项?

1 个答案:

答案 0 :(得分:1)

您正在从错误的层复制运行时文件

COPY --from=build /app .

尝试将其更改为

COPY --from=publish /app .

此外,您可能需要在构建和发布步骤中分离出路径:

RUN dotnet build "Fightplan_v1.csproj" -c Release -o /app/build
RUN dotnet publish "Fightplan_v1.csproj" -c Release -o /app/publish

,然后从发布文件夹复制运行时文件

COPY --from=publish /app/publish .

编辑。基本上,您需要将publish个工件复制到运行时,而不是build。构建将生成deps.json,它将列出所有外部依赖关系,并且在运行时此库正在使用NuGet缓存进行解析,如果为空,则将看到错误。要复制依赖项以及项目文件,您需要运行publish。 因此,我认为理论上dotnet build是可以省略的,仅用于在Docker构建的早期阶段发现编译错误。