gpt4 book ai didi

docker - 在使用 Paket 从项目构建的 Docker 镜像中找不到 Microsoft.AspNetCore.App 2.2.7

转载 作者:行者123 更新时间:2023-12-02 19:23:47 25 4
gpt4 key购买 nike

我有一个使用 Paket 的 F# 项目构建的 docker 镜像。在运行时,图像失败并显示:

It was not possible to find any compatible framework version The specified framework 'Microsoft.AspNetCore.App', version '2.2.7' was not found.



我的 dockerfile看起来像这样:
# Two stage build because Paket means project files reference external files
# via <Import Project="..\.paket\Paket.Restore.targets" />
# https://github.com/fsprojects/Paket/issues/3006#issuecomment-359750323

FROM microsoft/dotnet:2.2-sdk-alpine AS build
RUN apk update \
&& apk add --no-cache bash
WORKDIR /app

# copy fsproj and restore as distinct layers
COPY MyCompany.WebApi/MyCompany.WebApi.fsproj ./MyCompany.WebApi/
COPY NuGet.config ./

RUN dotnet restore MyCompany.WebApi/MyCompany.WebApi.fsproj --configfile NuGet.config

# copy everything else and build
COPY . ./
RUN dotnet publish MyCompany.WebApi/MyCompany.WebApi.fsproj -c Release -o out

# build runtime image
FROM microsoft/dotnet:2.2-sdk-alpine AS final
RUN apk update \
&& apk add --no-cache bash
WORKDIR /app
COPY --from=build /app/MyCompany.WebApi/out ./

ENTRYPOINT ["dotnet", "MyCompany.WebApi.dll"]

如果我使用 2.2-runtime-alpine 也会出现同样的问题作为 final 的基础.

我的 packet.lock包括以下几行:
// https://github.com/fsharp/FAKE/issues/2193:
version 5.216.0
...
source https://api.nuget.org/v3/index.json
...
nuget Microsoft.AspNetCore.App
...

我注意到我生成的 paket.dependencies指定 Microsoft.AspNetCore.App 的特定版本:
Microsoft.AspNetCore.App (2.2.7)
Microsoft.AspNet.WebApi.Client (>= 5.2.6 < 5.3) - restriction: >= netcoreapp2.2
Microsoft.AspNetCore (>= 2.2 < 2.3) - restriction: >= netcoreapp2.2
Microsoft.AspNetCore.Antiforgery (>= 2.2 < 2.3) - restriction: >= netcoreapp2.2

...虽然看起来我们不鼓励指定版本:

https://docs.microsoft.com/en-us/aspnet/core/fundamentals/metapackage-app?view=aspnetcore-2.2

所以我的问题是:有没有可能想出 Docker、Paket、F# 和 AspNetCore 的组合来协同工作?

编辑: paket.dependencies -> packet.lock
编辑2:这是入口点目录的列表,如下:
.:
total 18668
-rwxr--r-- 1 root root 190976 Aug 29 13:18 Dapper.dll
-rwxr--r-- 1 root root 2850168 Aug 2 19:03 FSharp.Core.dll
-rwxr--r-- 1 root root 243200 Apr 16 08:00 Fable.Core.dll
-rwxr--r-- 1 root root 342528 Feb 10 2019 Giraffe.dll
...lots more DLLs from Nuget dependencies
... some DLLs from our internal dependencies
-rw-r--r-- 1 root root 100670 Sep 12 13:23 MyCompany.WebApi.deps.json
-rwxr-xr-x 1 root root 61440 Sep 12 13:23 MyCompany.WebApi.dll
-rw-r--r-- 1 root root 10608 Sep 12 13:23 MyCompany.WebApi.pdb
-rw-r--r-- 1 root root 149 Sep 12 13:23 MyCompany.WebApi.runtimeconfig.json
-rwxr--r-- 1 root root 178824 Nov 28 2018 System.Net.Http.Formatting.dll
-rwxr--r-- 1 root root 23088 Sep 18 2018 System.Runtime.CompilerServices.Unsafe.dll
-rwxr--r-- 1 root root 29744 Feb 15 2019 System.Security.Cryptography.OpenSsl.dll
-rwxr--r-- 1 root root 189168 Nov 29 2018 System.Security.Cryptography.Pkcs.dll
-rwxr--r-- 1 root root 29760 Jul 19 2018 System.ServiceModel.Primitives.dll
-rwxr--r-- 1 root root 30784 Jul 19 2018 System.ServiceModel.dll
-rwxr--r-- 1 root root 759024 Nov 29 2018 System.Text.Encoding.CodePages.dll
-rwxr--r-- 1 root root 91136 Sep 16 2018 TaskBuilder.fs.dll
drwxr-xr-x 2 root root 4096 Sep 12 13:23 cs
drwxr-xr-x 2 root root 4096 Sep 12 13:23 de
drwxr-xr-x 2 root root 4096 Sep 12 13:23 es
drwxr-xr-x 2 root root 4096 Sep 12 13:23 fr
drwxr-xr-x 2 root root 4096 Sep 12 13:23 it
drwxr-xr-x 2 root root 4096 Sep 12 13:23 ja
drwxr-xr-x 2 root root 4096 Sep 12 13:23 ko
drwxr-xr-x 2 root root 4096 Sep 12 13:23 pl
-rwxr--r-- 1 root root 277504 Aug 30 2018 protobuf-net.dll
drwxr-xr-x 2 root root 4096 Sep 12 13:23 pt-BR
drwxr-xr-x 2 root root 4096 Sep 12 13:23 ru
drwxr-xr-x 4 root root 4096 Sep 12 13:23 runtimes
drwxr-xr-x 2 root root 4096 Sep 12 13:23 tr
drwxr-xr-x 2 root root 4096 Sep 12 13:23 zh-Hans
drwxr-xr-x 2 root root 4096 Sep 12 13:23 zh-Hant

./cs:
total 376
-rwxr--r-- 1 root root 33144 Aug 2 19:03 FSharp.Core.resources.dll
-rwxr--r-- 1 root root 308088 Aug 8 16:19 Microsoft.CodeAnalysis.CSharp.resources.dll
-rwxr--r-- 1 root root 34896 Aug 8 16:18 Microsoft.CodeAnalysis.resources.dll

./de:
total 392
-rwxr--r-- 1 root root 34168 Aug 2 19:03 FSharp.Core.resources.dll
-rwxr--r-- 1 root root 327544 Aug 8 16:19 Microsoft.CodeAnalysis.CSharp.resources.dll
-rwxr--r-- 1 root root 36216 Aug 8 16:18 Microsoft.CodeAnalysis.resources.dll

./es:
total 388
-rwxr--r-- 1 root root 33360 Aug 2 19:03 FSharp.Core.resources.dll
-rwxr--r-- 1 root root 321104 Aug 8 16:19 Microsoft.CodeAnalysis.CSharp.resources.dll
-rwxr--r-- 1 root root 35920 Aug 8 16:18 Microsoft.CodeAnalysis.resources.dll

./fr:
total 392
-rwxr--r-- 1 root root 33656 Aug 2 19:03 FSharp.Core.resources.dll
-rwxr--r-- 1 root root 327544 Aug 8 16:19 Microsoft.CodeAnalysis.CSharp.resources.dll
-rwxr--r-- 1 root root 36432 Aug 8 16:18 Microsoft.CodeAnalysis.resources.dll

./it:
total 392
-rwxr--r-- 1 root root 33144 Aug 2 19:03 FSharp.Core.resources.dll
-rwxr--r-- 1 root root 325496 Aug 8 16:19 Microsoft.CodeAnalysis.CSharp.resources.dll
-rwxr--r-- 1 root root 36216 Aug 8 16:18 Microsoft.CodeAnalysis.resources.dll

./ja:
total 428
-rwxr--r-- 1 root root 35704 Aug 2 19:03 FSharp.Core.resources.dll
-rwxr--r-- 1 root root 358776 Aug 8 16:19 Microsoft.CodeAnalysis.CSharp.resources.dll
-rwxr--r-- 1 root root 38264 Aug 8 16:18 Microsoft.CodeAnalysis.resources.dll

./ko:
total 396
-rwxr--r-- 1 root root 34680 Aug 2 19:03 FSharp.Core.resources.dll
-rwxr--r-- 1 root root 331336 Aug 8 16:19 Microsoft.CodeAnalysis.CSharp.resources.dll
-rwxr--r-- 1 root root 36728 Aug 8 16:18 Microsoft.CodeAnalysis.resources.dll

./pl:
total 396
-rwxr--r-- 1 root root 34168 Aug 2 19:03 FSharp.Core.resources.dll
-rwxr--r-- 1 root root 331128 Aug 8 16:19 Microsoft.CodeAnalysis.CSharp.resources.dll
-rwxr--r-- 1 root root 36216 Aug 8 16:18 Microsoft.CodeAnalysis.resources.dll

./pt-BR:
total 380
-rwxr--r-- 1 root root 32632 Aug 2 19:03 FSharp.Core.resources.dll
-rwxr--r-- 1 root root 316280 Aug 8 16:19 Microsoft.CodeAnalysis.CSharp.resources.dll
-rwxr--r-- 1 root root 35704 Aug 8 16:18 Microsoft.CodeAnalysis.resources.dll

./ru:
total 508
-rwxr--r-- 1 root root 39800 Aug 2 19:03 FSharp.Core.resources.dll
-rwxr--r-- 1 root root 430968 Aug 8 16:19 Microsoft.CodeAnalysis.CSharp.resources.dll
-rwxr--r-- 1 root root 42360 Aug 8 16:18 Microsoft.CodeAnalysis.resources.dll

./runtimes:
total 8
drwxr-xr-x 3 root root 4096 Sep 12 13:23 unix
drwxr-xr-x 3 root root 4096 Sep 12 13:23 win

./runtimes/unix:
total 4
drwxr-xr-x 4 root root 4096 Sep 12 13:23 lib

./runtimes/unix/lib:
total 8
drwxr-xr-x 2 root root 4096 Sep 12 13:23 netcoreapp2.1
drwxr-xr-x 2 root root 4096 Sep 12 13:23 netstandard2.0

./runtimes/unix/lib/netcoreapp2.1:
total 88
-rwxr--r-- 1 root root 86280 Feb 15 2019 System.Security.Cryptography.OpenSsl.dll

./runtimes/unix/lib/netstandard2.0:
total 1848
-rwxr--r-- 1 root root 1889344 Jul 19 2018 System.Private.ServiceModel.dll

./runtimes/win:
total 4
drwxr-xr-x 5 root root 4096 Sep 12 13:23 lib

./runtimes/win/lib:
total 12
drwxr-xr-x 2 root root 4096 Sep 12 13:23 netcoreapp2.0
drwxr-xr-x 2 root root 4096 Sep 12 13:23 netcoreapp2.1
drwxr-xr-x 2 root root 4096 Sep 12 13:23 netstandard2.0

./runtimes/win/lib/netcoreapp2.0:
total 744
-rwxr--r-- 1 root root 761392 Nov 29 2018 System.Text.Encoding.CodePages.dll

./runtimes/win/lib/netcoreapp2.1:
total 212
-rwxr--r-- 1 root root 214064 Nov 29 2018 System.Security.Cryptography.Pkcs.dll

./runtimes/win/lib/netstandard2.0:
total 1848
-rwxr--r-- 1 root root 1889344 Jul 19 2018 System.Private.ServiceModel.dll

./tr:
total 376
-rwxr--r-- 1 root root 32632 Aug 2 19:03 FSharp.Core.resources.dll
-rwxr--r-- 1 root root 312184 Aug 8 16:19 Microsoft.CodeAnalysis.CSharp.resources.dll
-rwxr--r-- 1 root root 35192 Aug 8 16:18 Microsoft.CodeAnalysis.resources.dll

./zh-Hans:
total 344
-rwxr--r-- 1 root root 31096 Aug 2 19:03 FSharp.Core.resources.dll
-rwxr--r-- 1 root root 278904 Aug 8 16:19 Microsoft.CodeAnalysis.CSharp.resources.dll
-rwxr--r-- 1 root root 33144 Aug 8 16:18 Microsoft.CodeAnalysis.resources.dll

./zh-Hant:
total 344
-rwxr--r-- 1 root root 30584 Aug 2 19:03 FSharp.Core.resources.dll
-rwxr--r-- 1 root root 280144 Aug 8 16:19 Microsoft.CodeAnalysis.CSharp.resources.dll
-rwxr--r-- 1 root root 33360 Aug 8 16:18 Microsoft.CodeAnalysis.resources.dll

最佳答案

我想我已经解决了这个问题。将基本镜像更改为我在 Microsoft 教程中找到的引用,并删除了 apk update阶段(因为这会返回带有此新基础镜像的非零退出代码)。所以这是我的dockerfile现在。

FROM mcr.microsoft.com/dotnet/core/sdk:2.2 AS build
WORKDIR /app

# copy fsproj and restore as distinct layers
COPY MyCompany.WebApi/MyCompany.WebApi.fsproj ./MyCompany.WebApi/
COPY NuGet.config ./

RUN dotnet restore MyCompany.WebApi/MyCompany.WebApi.fsproj --configfile NuGet.config

# copy everything else and build
COPY . ./
RUN dotnet publish MyCompany.WebApi/MyCompany.WebApi.fsproj -c Release -o out

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

ENTRYPOINT ["dotnet", "MyCompany.WebApi.dll"]

它现在启动正常,尚未测试功能!

我远非 Docker 或 Linux 专家,但我会大胆猜测 Alpine 镜像还没有 catch 最新的 dotnet 版本。我也猜想我在这个改变之后创建的图像比它需要的更胖,但我现在会采取“肥胖和工作”。

关于docker - 在使用 Paket 从项目构建的 Docker 镜像中找不到 Microsoft.AspNetCore.App 2.2.7,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57905186/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com